From 2fb2853cd1c26f5323d26ae7e7bea04fcbcc7807 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Tue, 10 May 2022 10:01:17 +0200 Subject: [PATCH 1/3] #8928 Added os quick report --- pandora_console/include/functions_os.php | 196 ++++++++-- .../include/lib/Dashboard/Widget.php | 4 + .../lib/Dashboard/Widgets/os_quick_report.php | 344 ++++++++++++++++++ 3 files changed, 514 insertions(+), 30 deletions(-) create mode 100644 pandora_console/include/lib/Dashboard/Widgets/os_quick_report.php diff --git a/pandora_console/include/functions_os.php b/pandora_console/include/functions_os.php index d616c3e94f..2b5b25c24d 100755 --- a/pandora_console/include/functions_os.php +++ b/pandora_console/include/functions_os.php @@ -14,54 +14,190 @@ // Get critical agents by using the status code in modules. function os_agents_critical($id_os) { - // TODO REVIEW ORACLE AND POSTGRES - return db_get_sql( - " - SELECT COUNT(*) - FROM tagente - WHERE tagente.disabled=0 AND - critical_count>0 AND id_os=$id_os" - ); + global $config; + + $table = (is_metaconsole() === true) ? 'tmetaconsole_agent' : 'tagente'; + + if (users_is_admin() === true) { + return db_get_sql( + sprintf( + 'SELECT COUNT(*) + FROM %s + WHERE tagente.disabled=0 AND + critical_count>0 AND id_os=%d', + $table, + $id_os + ) + ); + } else { + $groups = array_keys(users_get_groups($config['id_user'], 'AR', false)); + + return db_get_sql( + sprintf( + 'SELECT COUNT(*) + FROM %s + WHERE tagente.disabled=0 AND + critical_count>0 AND + id_os=%d AND id_grupo IN (%s)', + $table, + $id_os, + implode(',', $groups) + ) + ); + } } // Get ok agents by using the status code in modules. function os_agents_ok($id_os) { - return db_get_sql( - " - SELECT COUNT(*) - FROM tagente - WHERE tagente.disabled=0 AND - normal_count=total_count AND id_os=$id_os" - ); + global $config; + + $table = (is_metaconsole() === true) ? 'tmetaconsole_agent' : 'tagente'; + + if (users_is_admin() === true) { + return db_get_sql( + sprintf( + 'SELECT COUNT(*) + FROM %s + WHERE tagente.disabled=0 AND + normal_count=total_count AND id_os=%d', + $table, + $id_os + ) + ); + } else { + $groups = array_keys(users_get_groups($config['id_user'], 'AR', false)); + + return db_get_sql( + sprintf( + 'SELECT COUNT(*) + FROM %s + WHERE tagente.disabled=0 AND + normal_count=total_count AND + id_os=%d AND id_grupo IN (%s)', + $table, + $id_os, + implode(',', $groups) + ) + ); + } } // Get warning agents by using the status code in modules. function os_agents_warning($id_os) { - return db_get_sql( - " - SELECT COUNT(*) - FROM tagente - WHERE tagente.disabled=0 AND - critical_count=0 AND warning_count>0 AND id_os=$id_os" - ); + global $config; + + $table = (is_metaconsole() === true) ? 'tmetaconsole_agent' : 'tagente'; + + if (users_is_admin() === true) { + return db_get_sql( + sprintf( + 'SELECT COUNT(*) + FROM %s + WHERE tagente.disabled=0 AND + critical_count=0 AND warning_count>0 + AND id_os=%d', + $table, + $id_os + ) + ); + } else { + $groups = array_keys(users_get_groups($config['id_user'], 'AR', false)); + + return db_get_sql( + sprintf( + 'SELECT COUNT(*) + FROM %s + WHERE tagente.disabled=0 AND + critical_count=0 AND warning_count>0 AND + id_os=%d AND id_grupo IN (%s)', + $table, + $id_os, + implode(',', $groups) + ) + ); + } } // Get unknown agents by using the status code in modules. function os_agents_unknown($id_os) { - return db_get_sql( - " - SELECT COUNT(*) - FROM tagente - WHERE tagente.disabled=0 AND - critical_count=0 AND warning_count=0 AND - unknown_count>0 AND id_os=$id_os" - ); + global $config; + + $table = (is_metaconsole() === true) ? 'tmetaconsole_agent' : 'tagente'; + + if (users_is_admin() === true) { + return db_get_sql( + sprintf( + 'SELECT COUNT(*) + FROM %s + WHERE tagente.disabled=0 AND + critical_count=0 AND warning_count=0 AND + unknown_count>0 AND id_os=%d', + $table, + $id_os + ) + ); + } else { + $groups = array_keys(users_get_groups($config['id_user'], 'AR', false)); + + return db_get_sql( + sprintf( + 'SELECT COUNT(*) + FROM %s + WHERE tagente.disabled=0 AND + critical_count=0 AND warning_count=0 AND + unknown_count>0 AND id_os=%d AND id_grupo IN (%s)', + $table, + $id_os, + implode(',', $groups) + ) + ); + } +} + + +/** + * Get total agents + * + * @param integer $id_os OS id. + * + * @return array|boolean + */ +function os_agents_total(int $id_os) +{ + global $config; + + $table = (is_metaconsole() === true) ? 'tmetaconsole_agent' : 'tagente'; + + if (users_is_admin() === true) { + return db_get_sql( + sprintf( + 'SELECT COUNT(*) + FROM %s + WHERE tagente.disabled=0 AND id_os=%d', + $table, + $id_os + ) + ); + } else { + $groups = array_keys(users_get_groups($config['id_user'], 'AR', false)); + + return db_get_sql( + sprintf( + 'SELECT COUNT(*) + FROM %s + WHERE tagente.disabled=0 AND id_os=%d AND id_grupo IN (%s)', + $table, + $id_os, + implode(',', $groups) + ) + ); + } } diff --git a/pandora_console/include/lib/Dashboard/Widget.php b/pandora_console/include/lib/Dashboard/Widget.php index 320280718b..1c5904e74a 100644 --- a/pandora_console/include/lib/Dashboard/Widget.php +++ b/pandora_console/include/lib/Dashboard/Widget.php @@ -412,6 +412,10 @@ class Widget $className .= '\WuxWidget'; break; + case 'os_quick_report': + $className .= '\OsQuickReportWidget'; + break; + default: $className = false; break; diff --git a/pandora_console/include/lib/Dashboard/Widgets/os_quick_report.php b/pandora_console/include/lib/Dashboard/Widgets/os_quick_report.php new file mode 100644 index 0000000000..ca8a56e604 --- /dev/null +++ b/pandora_console/include/lib/Dashboard/Widgets/os_quick_report.php @@ -0,0 +1,344 @@ +width = $width; + + // Height. + $this->height = $height; + + // Cell Id. + $this->cellId = $cellId; + + // Widget ID. + $this->widgetId = $widgetId; + + // Dashboard ID. + $this->dashboardId = $dashboardId; + + // Options. + $this->values = $this->decoders($this->getOptionsWidget()); + + // Positions. + $this->position = $this->getPositionWidget(); + + // Page. + $this->page = basename(__FILE__); + + // ClassName. + $class = new \ReflectionClass($this); + $this->className = $class->getShortName(); + + // Title. + $this->title = __('OS quick report'); + + // Name. + if (empty($this->name) === true) { + $this->name = 'os_quick_report'; + } + + $this->overflow_scrollbars = false; + } + + + /** + * Decoders hack for retrocompability. + * + * @param array $decoder Values. + * + * @return array Returns the values ​​with the correct key. + */ + public function decoders(array $decoder): array + { + $values = []; + // Retrieve global - common inputs. + $values = parent::decoders($decoder); + + return $values; + } + + + /** + * Generates inputs for form (specific). + * + * @return array Of inputs. + * + * @throws Exception On error. + */ + public function getFormInputs(): array + { + // Retrieve global - common inputs. + $inputs = parent::getFormInputs(); + + return $inputs; + } + + + /** + * Get Post for widget. + * + * @return array + */ + public function getPost():array + { + // Retrieve global - common inputs. + $values = parent::getPost(); + + return $values; + } + + + /** + * Draw widget. + * + * @return string; + */ + public function load() + { + global $config; + + $values = $this->values; + + $result = []; + $os_array = os_get_os(); + foreach ($os_array as $os) { + $id_os = (int) $os['id_os']; + $total = os_agents_total($id_os); + if ((int) $total === 0) { + continue; + } + + $result[$id_os]['name'] = $os['name']; + $result[$id_os]['total'] = (int) $total; + $result[$id_os]['normal'] = (int) os_agents_ok($id_os); + $result[$id_os]['critical'] = (int) os_agents_critical($id_os); + $result[$id_os]['unknown'] = (int) os_agents_unknown($id_os); + } + + $output = ''; + if (empty($result) === false) { + $table = new \stdClass(); + + $table->class = 'info_table'; + $table->width = '100%'; + $table->cellpadding = 0; + $table->cellspacing = 0; + $table->size = []; + + $table->align = []; + $table->align[0] = 'left'; + $table->align[1] = 'left'; + $table->align[2] = 'left'; + $table->align[3] = 'left'; + $table->align[4] = 'left'; + $table->align[5] = 'left'; + + $table->head = []; + $table->head[0] = __('OS'); + $table->head[1] = __('OS name'); + $table->head[2] = ucfirst(__('total agents')); + $table->head[3] = ucfirst(__('normal agents')); + $table->head[4] = ucfirst(__('critical agents')); + $table->head[5] = ucfirst(__('unknown agents')); + + $table->headstyle = []; + $table->headstyle[0] = 'background-color: '.$values['background']; + $table->headstyle[1] = 'background-color: '.$values['background']; + $table->headstyle[2] = 'background-color: '.$values['background']; + $table->headstyle[3] = 'background-color: '.$values['background']; + $table->headstyle[4] = 'background-color: '.$values['background']; + $table->headstyle[5] = 'background-color: '.$values['background']; + + $table->style = []; + $table->style[0] = 'background-color: '.$values['background']; + $table->style[1] = 'background-color: '.$values['background']; + $table->style[2] = 'background-color: '.$values['background']; + $table->style[3] = 'background-color: '.$values['background']; + $table->style[4] = 'background-color: '.$values['background']; + $table->style[5] = 'background-color: '.$values['background']; + + foreach ($result as $id => $os) { + $data = []; + + $data[0] = ui_print_os_icon($id, false, true); + $data[1] = $os['name']; + $data[2] = $os['total']; + $data[3] = $os['normal']; + $data[4] = $os['critical']; + $data[5] = $os['unknown']; + + $table->data[] = $data; + } + + $output = html_print_table($table, true); + } else { + $output = 'No data available'; + } + + return $output; + } + + + /** + * Get description. + * + * @return string. + */ + public static function getDescription() + { + return __('OS quick report'); + } + + + /** + * Get Name. + * + * @return string. + */ + public static function getName() + { + return 'os_quick_report'; + } + + +} From 4699ec7a3f3735e055a53556ab891be4c67e935b Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Tue, 10 May 2022 13:44:10 +0200 Subject: [PATCH 2/3] #8928 Added img --- .../images/widgets/os_quick_report.png | Bin 0 -> 4619 bytes .../lib/Dashboard/Widgets/os_quick_report.php | 26 +++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 pandora_console/images/widgets/os_quick_report.png diff --git a/pandora_console/images/widgets/os_quick_report.png b/pandora_console/images/widgets/os_quick_report.png new file mode 100644 index 0000000000000000000000000000000000000000..eda6e7adbef45604008465892faad054f822f208 GIT binary patch literal 4619 zcmV+m67=nfP)FCjC~D;i3JB!gp0m8O*}HG=y?gK7cM~BylkD!<^Vzd!cklimV?M5KWp%Yr5_9B) z`W01m0GKDkC_Hyki@+6u`75eiLh$t+cjnxQFE?Zm0SFfQAN)1YDM0a2|Gk|Mh+(xHvb#-NCUttHq!h9_DOx=X0d>Epd9^bggiL9-1#dx86rmvhXBsIxZq@J>LxZd$>|^g*_qq#_q$CQ5>LJtOMfFHqk@+~?+d~kzRKa1TB430bu z}<1BOyP0;IB2VoEBJwi;;)fv!(>#hhQ6=~TylUi!Rx*vHRz?89&Pz;p4=;)Kd zD+3OR{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;mZN5=%ScLzBs2szw|2#y%G0WGh$;HEA1;%5 zccyUABr<6}%Vr!oV?{$<3$R1svTq*Vq^+kt7g~k6rTdCg_=7W z3|9?4-XBWRHRgd&6YyyQzZst9YD~K|`01*H{~vzcellpadding = 0; $table->cellspacing = 0; $table->size = []; + $table->size[0] = '10%'; + $table->size[1] = '10%'; + $table->size[2] = '20%'; + $table->size[3] = '20%'; + $table->size[4] = '20%'; + $table->size[5] = '20%'; $table->align = []; - $table->align[0] = 'left'; + $table->align[0] = 'center'; $table->align[1] = 'left'; - $table->align[2] = 'left'; - $table->align[3] = 'left'; - $table->align[4] = 'left'; - $table->align[5] = 'left'; + $table->align[2] = 'center'; + $table->align[3] = 'center'; + $table->align[4] = 'center'; + $table->align[5] = 'center'; $table->head = []; $table->head[0] = __('OS'); @@ -282,12 +288,12 @@ class OsQuickReportWidget extends Widget $table->head[5] = ucfirst(__('unknown agents')); $table->headstyle = []; - $table->headstyle[0] = 'background-color: '.$values['background']; + $table->headstyle[0] = 'text-align:center;background-color: '.$values['background']; $table->headstyle[1] = 'background-color: '.$values['background']; - $table->headstyle[2] = 'background-color: '.$values['background']; - $table->headstyle[3] = 'background-color: '.$values['background']; - $table->headstyle[4] = 'background-color: '.$values['background']; - $table->headstyle[5] = 'background-color: '.$values['background']; + $table->headstyle[2] = 'text-align:center;background-color: '.$values['background']; + $table->headstyle[3] = 'text-align:center;background-color: '.$values['background']; + $table->headstyle[4] = 'text-align:center;background-color: '.$values['background']; + $table->headstyle[5] = 'text-align:center;background-color: '.$values['background']; $table->style = []; $table->style[0] = 'background-color: '.$values['background']; From 644948c1b553b11bab3693239f23c3f798c48c71 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Tue, 10 May 2022 14:53:33 +0200 Subject: [PATCH 3/3] #8928 font size --- .../include/lib/Dashboard/Widgets/os_quick_report.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandora_console/include/lib/Dashboard/Widgets/os_quick_report.php b/pandora_console/include/lib/Dashboard/Widgets/os_quick_report.php index 512b46eb6d..c1bad5c63f 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/os_quick_report.php +++ b/pandora_console/include/lib/Dashboard/Widgets/os_quick_report.php @@ -298,10 +298,10 @@ class OsQuickReportWidget extends Widget $table->style = []; $table->style[0] = 'background-color: '.$values['background']; $table->style[1] = 'background-color: '.$values['background']; - $table->style[2] = 'background-color: '.$values['background']; - $table->style[3] = 'background-color: '.$values['background']; - $table->style[4] = 'background-color: '.$values['background']; - $table->style[5] = 'background-color: '.$values['background']; + $table->style[2] = 'font-size: 22px;background-color: '.$values['background']; + $table->style[3] = 'font-size: 22px;background-color: '.$values['background']; + $table->style[4] = 'font-size: 22px;background-color: '.$values['background']; + $table->style[5] = 'font-size: 22px;background-color: '.$values['background']; foreach ($result as $id => $os) { $data = [];