]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix #9780 allow multiple jobids in fileevents request
authorEric Bollengier <eric@baculasystems.com>
Thu, 5 Jan 2023 13:43:21 +0000 (08:43 -0500)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:57:00 +0000 (13:57 +0200)
bacula/src/cats/cats.h
bacula/src/cats/sql_create.c
bacula/src/cats/sql_list.c
bacula/src/dird/catreq.c
bacula/src/dird/ua_output.c
bacula/src/stored/bscan.c

index 832c13b2799fe0473bc2a0966bb431d1b81f9d39..98431d8a89cb39249859c7c8c292248276f8e29d 100644 (file)
@@ -733,13 +733,13 @@ class FILEEVENT_DBR: public SMARTALLOC
 {
 public:
    DBId_t FileIndex;            // FileIndex of the File
-   DBId_t JobId;                // JobId of the file
+   char *JobId;                // JobId of the file. For list only: can specify list or range of jobs
    DBId_t SourceJobId;          // Verify/Restore JobId
    char   Type;                 // antivirus, malware, lost file
    int    Severity;             // level of severity (0 OK, 100 Important)
    char   Description[MAX_NAME_LENGTH];
    char   Source[MAX_NAME_LENGTH];
-   FILEEVENT_DBR(): FileIndex(0), JobId(0), Type(0),
+   FILEEVENT_DBR(): FileIndex(0), JobId(NULL), Type(0),
                     Severity(0)
    {
       *Description = *Source = 0;
@@ -747,7 +747,7 @@ public:
    ~FILEEVENT_DBR() {};
 
    bool unpack(uint32_t stream, const char *data, int data_len) {
-      SourceJobId = JobId = FileIndex = 0;
+      SourceJobId = FileIndex = 0;
       if (scan_string(data, "%c %d %127s %127s 0", &Type, &Severity, Source, Description) == 4) {
          unbash_spaces(Source);
          unbash_spaces(Description);
index 15cefb5d7e8896c5f3a983cebf6cd9912a0ac885..73dbc1bc6d8bfb720ace1b8de1f9a1b3ee20926a 100644 (file)
@@ -1487,7 +1487,7 @@ bool BDB::bdb_create_fileevent_record(JCR *jcr, FILEEVENT_DBR *event)
    bdb_escape_string(jcr, esc1, event->Description, strlen(event->Description));
    bdb_escape_string(jcr, esc2, event->Source, strlen(event->Source));
    Mmsg(cmd, "INSERT INTO FileEvents (SourceJobId, JobId, FileIndex, Type, Description, Severity, Source) "
-        " VALUES (%lu, %lu, %ld, '%c', '%s', %d, '%s')",
+        " VALUES (%lu, %s, %ld, '%c', '%s', %d, '%s')",
         event->SourceJobId, event->JobId, event->FileIndex, event->Type, esc1, event->Severity, esc2);
    ret = bdb_sql_query(cmd, NULL, (void *)NULL);
    bdb_unlock();
index b834fa6372dc396ad2819c8729d28a44bc7e7ed7..68fd6982da85bb83e6149233e4ce6ebbc3e95657 100644 (file)
@@ -652,7 +652,7 @@ void BDB::bdb_list_fileevents_records(JCR *jcr, FILEEVENT_DBR *rec,
    POOL_MEM tmp, filter;
    char ed1[50];
 
-   Mmsg(filter, "FileEvents.JobId=%s ", edit_int64(rec->JobId, ed1));
+   Mmsg(filter, "FileEvents.JobId in (%s) ", rec->JobId);
 
    if (rec->FileIndex > 0) {
       Mmsg(tmp, "AND FileEvents.FileIndex=%s ", edit_int64(rec->FileIndex, ed1));
index 7c9710378ea21713beae7ecf6ffeabc0cf571e1d..5e4157d1c72d1e8bbc6ce81dc19d1f8ade55d78b 100644 (file)
@@ -132,12 +132,13 @@ static bool catreq_fileevent(JCR *jcr, DBId_t FileIndex, const char *p)
    FILEEVENT_DBR event;
    bool ok=false;
    uint32_t t1, t2, t3, t4;
+   char ed1[50];
    event.FileIndex = FileIndex;
 
    /* If the string is going through the attribute flow, we don't have the CatReq header */
    if (scan_string(p, FileEvent_add, &event.Type, &event.Severity, event.Source, event.Description) == 4)
    {
-      event.JobId = jcr->JobId; // Might need to look for previous jobid for example
+      event.JobId = edit_int64(jcr->JobId, ed1); // Might need to look for previous jobid for example
       event.FileIndex = FileIndex;
       ok = true;
 
@@ -145,7 +146,7 @@ static bool catreq_fileevent(JCR *jcr, DBId_t FileIndex, const char *p)
    } else if (scan_string(p, FileEvent_fd_add, &t1, &t2, &t3, &t4,
                           &event.Type, &event.Severity, event.Source, event.Description) == 8)
    {
-      event.JobId = jcr->previous_jr.JobId;
+      event.JobId = edit_int64(jcr->previous_jr.JobId, ed1);
       ok = true;
    }
    if (ok) {
index f925a950a781205f31f2cf34e501561b74df317a..f878b867e1b0c16dff1daf7813161d47c6eb4293 100644 (file)
@@ -628,8 +628,8 @@ static int do_list_cmd(UAContext *ua, const char *cmd, e_list_type llist)
       } else if (strcasecmp(ua->argk[i], NT_("fileevents")) == 0) {
          FILEEVENT_DBR event;
          for (j=i+1; j<ua->argc; j++) {
-            if (strcasecmp(ua->argk[j], NT_("jobid")) == 0 && ua->argv[j]) {
-               event.JobId = str_to_int64(ua->argv[j]);
+            if (strcasecmp(ua->argk[j], NT_("jobid")) == 0 && ua->argv[j] && is_a_number_list(ua->argv[j])) {
+               event.JobId = ua->argv[j];
 
             } else if (strcasecmp(ua->argk[j], NT_("fileindex")) == 0 && ua->argv[j]) {
                event.FileIndex = str_to_int64(ua->argv[j]);
index 98f7cb8300c85f1fc5383c6598fe92ae6e0ca7c4..2b4b4c4b6f949e3f0fff15bb1cc4baacb0ee5da4 100644 (file)
@@ -1012,7 +1012,8 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec)
                rec->VolSessionId, rec->VolSessionTime);
          break;
       }
-      fevent.SourceJobId = fevent.JobId = mjcr->JobId;
+      fevent.SourceJobId = mjcr->JobId;
+      fevent.JobId = edit_int64(mjcr->JobId, ec1);
       fevent.FileIndex = mjcr->JobFiles;
       if (!db_create_fileevent_record(mjcr, mjcr->db, &fevent)) {
          Jmsg2(mjcr, M_ERROR, 0, _("Failed to insert FileEvent record for file: %d. err: %s\n"),