Author: timopollmeier
Date: 2016-09-21 11:03:46 +0200 (Wed, 21 Sep 2016)
New Revision: 26239

Modified:
   trunk/openvas-manager/ChangeLog
   trunk/openvas-manager/doc/omp.html
   trunk/openvas-manager/doc/omp.rnc
   trunk/openvas-manager/src/manage.h
   trunk/openvas-manager/src/manage_sql.c
   trunk/openvas-manager/src/omp.c
   trunk/openvas-manager/src/schema_formats/XML/OMP.xml.in
Log:
        * src/manage_sql.c (task_average_scan_duration): New function.
        (scan_start_time_uuid): New function.

        * src/manage.h (task_average_scan_duration): New function prototype.
        (scan_start_time_uuid): New function prototype.

        * src/omp.c (send_reports): Add scan start time to reports.
        (handle_get_tasks): Add scan start time to reports and add average
        scan duration.

        * src/html/XML/OMP.xml (get_tasks): Add new average_duration response
        element.

        * doc/omp.html, doc/omp.rnc: Update from source.

Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog     2016-09-21 08:01:42 UTC (rev 26238)
+++ trunk/openvas-manager/ChangeLog     2016-09-21 09:03:46 UTC (rev 26239)
@@ -1,3 +1,20 @@
+2016-09-21  Timo Pollmeier <timo.pollme...@greenbone.net>
+
+       * src/manage_sql.c (task_average_scan_duration): New function.
+       (scan_start_time_uuid): New function.
+
+       * src/manage.h (task_average_scan_duration): New function prototype.
+       (scan_start_time_uuid): New function prototype.
+
+       * src/omp.c (send_reports): Add scan start time to reports.
+       (handle_get_tasks): Add scan start time to reports and add average
+       scan duration.
+
+       * src/html/XML/OMP.xml (get_tasks): Add new average_duration response
+       element.
+
+       * doc/omp.html, doc/omp.rnc: Update from source.
+
 2016-09-21  Christian Fischer <christian.fisc...@greenbone.net>
 
        * INSTALL: Added apt-get install prerequisites 

Modified: trunk/openvas-manager/doc/omp.html
===================================================================
--- trunk/openvas-manager/doc/omp.html  2016-09-21 08:01:42 UTC (rev 26238)
+++ trunk/openvas-manager/doc/omp.html  2016-09-21 09:03:46 UTC (rev 26239)
@@ -31847,6 +31847,11 @@
 </li></ul>
 </li>
 <li>
+              &lt;<b>average_duration</b>&gt;
+              ?<div style="margin-left: 15px; display: inline;">Average scan 
duration in seconds.</div>
+<ul style="list-style: none"></ul>
+</li>
+<li>
               &lt;<b>result_count</b>&gt;
               <div style="margin-left: 15px; display: inline;">Result count 
for the entire task.</div>
 <ul style="list-style: none"></ul>
@@ -32095,6 +32100,7 @@
            &amp; get_tasks_response_task_last_report?
            &amp; get_tasks_response_task_second_last_report?
            &amp; get_tasks_response_task_reports*
+           &amp; get_tasks_response_task_average_duration?
            &amp; get_tasks_response_task_result_count
            &amp; get_tasks_response_task_preferences )
            | ( get_tasks_response_task_name
@@ -32852,6 +32858,12 @@
        severity
      }
 
+get_tasks_response_task_average_duration
+ = element average_duration
+     {
+       text
+     }
+
 get_tasks_response_task_result_count
  = element result_count
      {
@@ -34257,6 +34269,7 @@
             GET_ASSETS             Get all assets.
             GET_CONFIGS            Get all configs.
             GET_CREDENTIALS        Get all credentials.
+            GET_FEEDS              Get details of one or all feeds this 
Manager uses.
             GET_FILTERS            Get all filters.
             GET_GROUPS             Get all groups.
             GET_INFO               Get raw information for a given item.

Modified: trunk/openvas-manager/doc/omp.rnc
===================================================================
--- trunk/openvas-manager/doc/omp.rnc   2016-09-21 08:01:42 UTC (rev 26238)
+++ trunk/openvas-manager/doc/omp.rnc   2016-09-21 09:03:46 UTC (rev 26239)
@@ -16869,6 +16869,7 @@
            & get_tasks_response_task_last_report?
            & get_tasks_response_task_second_last_report?
            & get_tasks_response_task_reports*
+           & get_tasks_response_task_average_duration?
            & get_tasks_response_task_result_count
            & get_tasks_response_task_preferences )
            | ( get_tasks_response_task_name
@@ -17694,6 +17695,13 @@
        severity
      }
 
+# Average scan duration in seconds.
+get_tasks_response_task_average_duration
+ = element average_duration
+     {
+       text
+     }
+
 # Result count for the entire task.
 get_tasks_response_task_result_count
  = element result_count

Modified: trunk/openvas-manager/src/manage.h
===================================================================
--- trunk/openvas-manager/src/manage.h  2016-09-21 08:01:42 UTC (rev 26238)
+++ trunk/openvas-manager/src/manage.h  2016-09-21 09:03:46 UTC (rev 26239)
@@ -679,6 +679,9 @@
 int
 trash_task_writable (task_t);
 
+int
+task_average_scan_duration (task_t);
+
 char*
 task_owner_name (task_t);
 
@@ -1238,6 +1241,9 @@
 scan_start_time_epoch (report_t);
 
 char*
+scan_start_time_uuid (const char *);
+
+char*
 scan_end_time_uuid (const char *);
 
 void

Modified: trunk/openvas-manager/src/manage_sql.c
===================================================================
--- trunk/openvas-manager/src/manage_sql.c      2016-09-21 08:01:42 UTC (rev 
26238)
+++ trunk/openvas-manager/src/manage_sql.c      2016-09-21 09:03:46 UTC (rev 
26239)
@@ -13067,6 +13067,24 @@
 }
 
 /**
+ * @brief Get the average duration of all finished reports of a task.
+ *
+ * @param[in]  uuid  The report associated with the scan.
+ *
+ * @return Average scan duration in seconds.
+ */
+int
+task_average_scan_duration (task_t task)
+{
+  return sql_int ("SELECT avg (end_time - start_time) FROM reports"
+                  " WHERE task = %llu"
+                  "   AND scan_run_status = %d"
+                  "   AND coalesce (end_time, 0) != 0"
+                  "   AND coalesce (start_time, 0) != 0;",
+                  task, TASK_STATUS_DONE);
+}
+
+/**
  * @brief Initialize the manage library for a process.
  *
  * Open the SQL database, attach secondary databases, and define functions.
@@ -22217,6 +22235,24 @@
 }
 
 /**
+ * @brief Get the start time of a scan.
+ *
+ * @param[in]  uuid  The report associated with the scan.
+ *
+ * @return Start time of scan, in a newly allocated string.
+ */
+char*
+scan_start_time_uuid (const char *uuid)
+{
+  char *time, *quoted_uuid;
+  quoted_uuid = sql_quote (uuid);
+  time = sql_string ("SELECT iso_time (start_time)"
+                     " FROM reports WHERE uuid = '%s';",
+                     quoted_uuid);
+  return time ? time : g_strdup ("");
+}
+
+/**
  * @brief Set the start time of a scan.
  *
  * @param[in]  report     The report associated with the scan.

Modified: trunk/openvas-manager/src/omp.c
===================================================================
--- trunk/openvas-manager/src/omp.c     2016-09-21 08:01:42 UTC (rev 26238)
+++ trunk/openvas-manager/src/omp.c     2016-09-21 09:03:46 UTC (rev 26239)
@@ -10627,7 +10627,7 @@
       gchar *uuid, *timestamp, *msg;
       int debugs, false_positives, holes, infos, logs, warnings, run_status;
       double severity;
-      char *scan_end;
+      char *scan_start, *scan_end;
 
       uuid = report_uuid (index);
 
@@ -10648,10 +10648,12 @@
       g_debug ("     %s\n", uuid);
 
       report_scan_run_status (index, &run_status);
+      scan_start = scan_start_time (index);
       scan_end = scan_end_time (index);
       msg = g_strdup_printf ("<report"
                              " id=\"%s\">"
                              "<timestamp>%s</timestamp>"
+                             "<scan_start>%s</scan_start>"
                              "<scan_end>%s</scan_end>"
                              "<scan_run_status>%s</scan_run_status>"
                              "<result_count>"
@@ -10666,6 +10668,7 @@
                              "</report>",
                              uuid,
                              timestamp,
+                             scan_start,
                              scan_end,
                              run_status_name
                               (run_status ? run_status
@@ -10677,6 +10680,7 @@
                              warnings,
                              false_positives,
                              severity);
+      free (scan_start);
       free (scan_end);
       g_free (timestamp);
       if (send_to_client (msg, write_to_client, write_to_client_data))
@@ -19530,7 +19534,7 @@
           if (running_report)
             {
               gchar *timestamp;
-              char *scan_end, *current_report_id;
+              char *scan_start, *scan_end, *current_report_id;
 
               current_report_id = report_uuid (running_report);
 
@@ -19539,6 +19543,7 @@
                          " of report, aborting",
                          __FUNCTION__);
 
+              scan_start = scan_start_time_uuid (current_report_id),
               scan_end = scan_end_time_uuid (current_report_id),
 
               current_report = g_strdup_printf ("<current_report>"
@@ -19546,6 +19551,9 @@
                                                 "<timestamp>"
                                                 "%s"
                                                 "</timestamp>"
+                                                "<scan_start>"
+                                                "%s"
+                                                "</scan_start>"
                                                 "<scan_end>"
                                                 "%s"
                                                 "</scan_end>"
@@ -19553,8 +19561,10 @@
                                                 "</current_report>",
                                                 current_report_id,
                                                 timestamp,
+                                                scan_start,
                                                 scan_end);
               free (current_report_id);
+              free (scan_start);
               free (scan_end);
               g_free (timestamp);
             }
@@ -19565,7 +19575,7 @@
           if (first_report_id)
             {
               gchar *timestamp;
-              char *scan_end;
+              char *scan_start, *scan_end;
 
               // TODO Could skip this count for tasks page.
               if (report_counts (first_report_id,
@@ -19582,13 +19592,15 @@
                          " first report, aborting",
                          __FUNCTION__);
 
-              scan_end = scan_end_time_uuid (first_report_id),
+              scan_start = scan_start_time_uuid (first_report_id);
+              scan_end = scan_end_time_uuid (first_report_id);
 
               first_report = g_strdup_printf ("<first_report>"
                                               "<report id=\"%s\">"
                                               "<timestamp>"
                                               "%s"
                                               "</timestamp>"
+                                              "<scan_start>%s</scan_start>"
                                               "<scan_end>%s</scan_end>"
                                               "<result_count>"
                                               "<debug>%i</debug>"
@@ -19607,6 +19619,7 @@
                                               "</first_report>",
                                               first_report_id,
                                               timestamp,
+                                              scan_start,
                                               scan_end,
                                               debugs,
                                               holes_2,
@@ -19615,6 +19628,7 @@
                                               warnings_2,
                                               false_positives,
                                               severity_2);
+              free (scan_start);
               free (scan_end);
               g_free (timestamp);
             }
@@ -19625,7 +19639,7 @@
           if (second_last_report_id)
             {
               gchar *timestamp;
-              char *scan_end;
+              char *scan_start, *scan_end;
 
               /* If the first report is the second last report then skip
                 * doing the count again. */
@@ -19646,12 +19660,14 @@
                          " second report, aborting",
                          __FUNCTION__);
 
-              scan_end = scan_end_time_uuid (second_last_report_id),
+              scan_start = scan_start_time_uuid (second_last_report_id);
+              scan_end = scan_end_time_uuid (second_last_report_id);
 
               second_last_report = g_strdup_printf
                                     ("<second_last_report>"
                                      "<report id=\"%s\">"
                                      "<timestamp>%s</timestamp>"
+                                     "<scan_start>%s</scan_start>"
                                      "<scan_end>%s</scan_end>"
                                      "<result_count>"
                                      "<debug>%i</debug>"
@@ -19668,6 +19684,7 @@
                                      "</second_last_report>",
                                      second_last_report_id,
                                      timestamp,
+                                     scan_start,
                                      scan_end,
                                      debugs,
                                      holes_2,
@@ -19676,6 +19693,7 @@
                                      warnings_2,
                                      false_positives,
                                      severity_2);
+              free (scan_start);
               free (scan_end);
               g_free (timestamp);
             }
@@ -19686,7 +19704,7 @@
           if (last_report_id)
             {
               gchar *timestamp;
-              char *scan_end;
+              char *scan_start, *scan_end;
 
               /* If the last report is the first report or the second
                 * last report, then reuse the counts from before. */
@@ -19719,11 +19737,13 @@
                          " last report, aborting",
                          __FUNCTION__);
 
+              scan_start = scan_start_time_uuid (last_report_id);
               scan_end = scan_end_time_uuid (last_report_id);
 
               last_report = g_strdup_printf ("<last_report>"
                                              "<report id=\"%s\">"
                                              "<timestamp>%s</timestamp>"
+                                             "<scan_start>%s</scan_start>"
                                              "<scan_end>%s</scan_end>"
                                              "<result_count>"
                                              "<debug>%i</debug>"
@@ -19742,6 +19762,7 @@
                                              "</last_report>",
                                              last_report_id,
                                              timestamp,
+                                             scan_start,
                                              scan_end,
                                              debugs,
                                              holes,
@@ -19750,6 +19771,7 @@
                                              warnings,
                                              false_positives,
                                              severity);
+              free (scan_start);
               free (scan_end);
               g_free (timestamp);
             }
@@ -20054,6 +20076,15 @@
             }
           cleanup_iterator (&alerts);
 
+          if (get_tasks_data->get.details
+              || get_tasks_data->get.id)
+            {
+              SENDF_TO_CLIENT_OR_FAIL ("<average_duration>"
+                                       "%d"
+                                       "</average_duration>",
+                                       task_average_scan_duration (index));
+            }
+
           if (get_tasks_data->get.details)
             {
               /* The detailed version. */

Modified: trunk/openvas-manager/src/schema_formats/XML/OMP.xml.in
===================================================================
--- trunk/openvas-manager/src/schema_formats/XML/OMP.xml.in     2016-09-21 
08:01:42 UTC (rev 26238)
+++ trunk/openvas-manager/src/schema_formats/XML/OMP.xml.in     2016-09-21 
09:03:46 UTC (rev 26239)
@@ -20830,6 +20830,7 @@
               <o><e>last_report</e></o>
               <o><e>second_last_report</e></o>
               <any><e>reports</e></any>
+              <o><e>average_duration</e></o>
               <e>result_count</e>
               <e>preferences</e>
             </g>
@@ -21560,6 +21561,11 @@
           </ele>
         </ele>
         <ele>
+          <name>average_duration</name>
+          <summary>Average scan duration in seconds</summary>
+          <pattern>text</pattern>
+        </ele>
+        <ele>
           <name>result_count</name>
           <summary>Result count for the entire task</summary>
           <pattern>text</pattern>

_______________________________________________
Openvas-commits mailing list
Openvas-commits@wald.intevation.org
https://lists.wald.intevation.org/cgi-bin/mailman/listinfo/openvas-commits

Reply via email to