]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Add UnixTime to JSON output of the .jlist events command
authorEric Bollengier <eric@baculasystems.com>
Thu, 8 Apr 2021 08:37:34 +0000 (10:37 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:03:01 +0000 (09:03 +0100)
bacula/src/cats/sql_cmds.c
bacula/src/cats/sql_cmds.h
bacula/src/cats/sql_list.c

index d892e1e2309a0e3338e19efbde33259206da195d..43c6c2629f41e4da1b9435a1f9161d2f45b2023b 100644 (file)
@@ -1048,6 +1048,15 @@ const char *expired_volumes[] = {
      " %s "
 };
 
+const char *to_unix_timestamp[] = {
+   /* MySQL */
+   "UNIX_TIMESTAMP(%s)",
+   /* PostgreSQL */
+   "EXTRACT(EPOCH FROM %s)",
+   /* SQLite */
+   "strftime('%%s', %s)" 
+};
+
 const char *expires_in[] = {
    /* MySQL */
    "(GREATEST(0, CAST(UNIX_TIMESTAMP(LastWritten) + Media.VolRetention AS SIGNED) - UNIX_TIMESTAMP(NOW())))",
index bac92eaee385502a18824ee939b62ae150d1349a..fc13a05cd5b0f328a7b4c15100ec29d3adccba26 100644 (file)
@@ -45,6 +45,7 @@ extern const char CATS_IMP_EXP *create_temp_basefile[];
 extern const char CATS_IMP_EXP *create_temp_new_basefile[];
 extern const char CATS_IMP_EXP *del_MAC;
 extern const char CATS_IMP_EXP *drop_deltabs[];
+extern const char CATS_IMP_EXP *to_unix_timestamp[];
 extern const char CATS_IMP_EXP *expired_volumes[];
 extern const char CATS_IMP_EXP *fill_jobhisto;
 extern const char CATS_IMP_EXP *get_restore_objects;
index ef7dc87d7ba3d8be88e0f2fcfd461892d3ebd861..65b8ea2031b7b8f60d7a0e42d08489341d87457e 100644 (file)
@@ -606,6 +606,18 @@ void BDB::bdb_list_events_records(JCR *jcr, EVENTS_DBR *rec,
         where.c_str(),
         rec->order ? "DESC" : "ASC",
         str_limit.c_str());
+
+   } else if (type == JSON_LIST) {
+      Mmsg(tmp2, to_unix_timestamp[bdb_get_type_index()], "EventsTime");
+      Mmsg(cmd,
+   "SELECT EventsTime AS Time, %s AS UnixTime, EventsCode AS Code, EventsDaemon AS Daemon, EventsRef AS Ref, EventsType AS Type, EventsSource AS Source, EventsText AS Events "
+     "FROM Events "
+    "%s ORDER BY Events.EventsTime %s %s",
+        tmp2.c_str(),
+        where.c_str(),
+        rec->order ? "DESC" : "ASC",
+        str_limit.c_str());
+
    } else {
       Mmsg(cmd,
    "SELECT EventsTime AS Time, EventsCode AS Code, EventsDaemon AS Daemon, EventsRef AS Ref, EventsType AS Type, EventsSource AS Source, EventsText AS Events "