diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index bb54c56b4c..8c24bcb56a 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 7.0NG.750-201029 +Version: 7.0NG.750-201103 Architecture: all Priority: optional Section: admin diff --git a/pandora_agents/unix/DEBIAN/make_deb_package.sh b/pandora_agents/unix/DEBIAN/make_deb_package.sh index 7e6e85035c..664fc368ed 100644 --- a/pandora_agents/unix/DEBIAN/make_deb_package.sh +++ b/pandora_agents/unix/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.750-201029" +pandora_version="7.0NG.750-201103" echo "Test if you has the tools for to make the packages." whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index d55e379f01..3d0a47fcda 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -55,7 +55,7 @@ my $Sem = undef; my $ThreadSem = undef; use constant AGENT_VERSION => '7.0NG.750'; -use constant AGENT_BUILD => '201029'; +use constant AGENT_BUILD => '201103'; # Agent log default file size maximum and instances use constant DEFAULT_MAX_LOG_SIZE => 600000; diff --git a/pandora_agents/unix/pandora_agent.redhat.spec b/pandora_agents/unix/pandora_agent.redhat.spec index 698b2439d2..1e4ad58036 100644 --- a/pandora_agents/unix/pandora_agent.redhat.spec +++ b/pandora_agents/unix/pandora_agent.redhat.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 7.0NG.750 -%define release 201029 +%define release 201103 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent.spec b/pandora_agents/unix/pandora_agent.spec index 8d18a817fe..057b26df2a 100644 --- a/pandora_agents/unix/pandora_agent.spec +++ b/pandora_agents/unix/pandora_agent.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 7.0NG.750 -%define release 201029 +%define release 201103 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent_installer b/pandora_agents/unix/pandora_agent_installer index 81a292285e..e08e30678b 100755 --- a/pandora_agents/unix/pandora_agent_installer +++ b/pandora_agents/unix/pandora_agent_installer @@ -10,7 +10,7 @@ # ********************************************************************** PI_VERSION="7.0NG.750" -PI_BUILD="201029" +PI_BUILD="201103" OS_NAME=`uname -s` FORCE=0 diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index f6493723fd..6228d5b274 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{201029} +{201103} ViewReadme {Yes} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index bac75d8cd5..d31a184151 100644 --- a/pandora_agents/win32/pandora.cc +++ b/pandora_agents/win32/pandora.cc @@ -30,7 +30,7 @@ using namespace Pandora; using namespace Pandora_Strutils; #define PATH_SIZE _MAX_PATH+1 -#define PANDORA_VERSION ("7.0NG.750(Build 201029)") +#define PANDORA_VERSION ("7.0NG.750(Build 201103)") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index 070d4c6fbd..3bdb9fe63b 100644 --- a/pandora_agents/win32/versioninfo.rc +++ b/pandora_agents/win32/versioninfo.rc @@ -11,7 +11,7 @@ BEGIN VALUE "LegalCopyright", "Artica ST" VALUE "OriginalFilename", "PandoraAgent.exe" VALUE "ProductName", "Pandora FMS Windows Agent" - VALUE "ProductVersion", "(7.0NG.750(Build 201029))" + VALUE "ProductVersion", "(7.0NG.750(Build 201103))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index 304b66c7a6..395cdae6ad 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 7.0NG.750-201029 +Version: 7.0NG.750-201103 Architecture: all Priority: optional Section: admin diff --git a/pandora_console/DEBIAN/make_deb_package.sh b/pandora_console/DEBIAN/make_deb_package.sh index a7ca73a213..b45e60e545 100644 --- a/pandora_console/DEBIAN/make_deb_package.sh +++ b/pandora_console/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.750-201029" +pandora_version="7.0NG.750-201103" package_pear=0 package_pandora=1 diff --git a/pandora_console/extensions/resource_exportation.php b/pandora_console/extensions/resource_exportation.php index 3946ec053d..16cf674ab6 100755 --- a/pandora_console/extensions/resource_exportation.php +++ b/pandora_console/extensions/resource_exportation.php @@ -92,7 +92,11 @@ function output_xml_report($id) $group = db_get_value('nombre', 'tgrupo', 'id_grupo', $report['id_group']); echo '\n"; - $items = db_get_all_rows_field_filter('treport_content', 'id_report', $report['id_report']); + $items = db_get_all_rows_field_filter( + 'treport_content', + 'id_report', + $report['id_report'] + ); foreach ($items as $item) { echo "\n"; echo ''.io_safe_output($item['type'])."\n"; diff --git a/pandora_console/extensions/resource_registration.php b/pandora_console/extensions/resource_registration.php index dae61e3a78..80fed2cf6c 100755 --- a/pandora_console/extensions/resource_registration.php +++ b/pandora_console/extensions/resource_registration.php @@ -37,8 +37,16 @@ function insert_item_report($report_id, $values) ui_print_result_message( $result, - sprintf(__("Success add '%s' item in report '%s'."), $values['type'], $name), - sprintf(__("Error create '%s' item in report '%s'."), $values['type'], $name) + sprintf( + __("Success add '%s' item in report '%s'."), + $values['type'], + $name + ), + sprintf( + __("Error create '%s' item in report '%s'."), + $values['type'], + $name + ) ); } } @@ -55,9 +63,12 @@ function process_upload_xml_report($xml, $group_filter=0) $posible_name = $values['name']; $exist = true; $loops = 30; - // Loops to exit or tries + // Loops to exit or tries. while ($exist && $loops > 0) { - $exist = (bool) db_get_row_filter('treport', ['name' => io_safe_input($posible_name)]); + $exist = (bool) db_get_row_filter( + 'treport', + ['name' => io_safe_input($posible_name)] + ); if ($exist) { $loops--; @@ -74,7 +85,7 @@ function process_upload_xml_report($xml, $group_filter=0) ); break; } else if ($loops != 30) { - ui_print_error_message( + ui_print_warning_message( sprintf( __("Warning create '%s' report, the name exist, the report have a name %s."), $reportElement->name, @@ -89,13 +100,22 @@ function process_upload_xml_report($xml, $group_filter=0) break; } - $id_group = db_get_value('id_grupo', 'tgrupo', 'nombre', $reportElement->group); - if ($id_group === false) { - ui_print_error_message(__("Error the report haven't group.")); - break; + if (isset($reportElement->group) === true + && empty($reportElement->group) === false + ) { + $id_group = db_get_value( + 'id_grupo', + 'tgrupo', + 'nombre', + $reportElement->group + ); + if ($id_group === false) { + ui_print_error_message(__("Error the report haven't group.")); + break; + } } - if (isset($reportElement->description)) { + if (isset($reportElement->description) === true) { $values['description'] = $reportElement->description; } @@ -108,9 +128,19 @@ function process_upload_xml_report($xml, $group_filter=0) ); if ($id_report) { - db_pandora_audit('Report management', 'Create report '.$id_report, false, false); + db_pandora_audit( + 'Report management', + 'Create report '.$id_report, + false, + false + ); } else { - db_pandora_audit('Report management', 'Fail to create report', false, false); + db_pandora_audit( + 'Report management', + 'Fail to create report', + false, + false + ); break; } @@ -119,45 +149,52 @@ function process_upload_xml_report($xml, $group_filter=0) $values = []; $values['id_report'] = $id_report; - if (isset($item['description'])) { + if (isset($item['description']) === true) { $values['description'] = io_safe_input($item['description']); } - if (isset($item['period'])) { + if (isset($item['period']) === true) { $values['period'] = io_safe_input($item['period']); } - if (isset($item['type'])) { + if (isset($item['type']) === true) { $values['type'] = io_safe_input($item['type']); } $agents_item = []; - if (isset($item['agent'])) { + if (isset($item['agent']) === true) { $agents = agents_get_agents( ['id_grupo' => $group_filter], [ 'id_agente', - 'nombre', + 'alias', ] ); - $agent_clean = str_replace(['[', ']'], '', $item['agent']); + $agent_clean = str_replace( + [ + '[', + ']', + ], + '', + io_safe_output($item['agent']) + ); $regular_expresion = ($agent_clean != $item['agent']); foreach ($agents as $agent) { if ($regular_expresion) { - if ((bool) preg_match('/'.$agent_clean.'/', io_safe_output($agent['nombre']))) { - $agents_item[$agent['id_agente']]['name'] = $agent['nombre']; + if ((bool) preg_match('/'.$agent_clean.'/', io_safe_output($agent['alias']))) { + $agents_item[$agent['id_agente']]['name'] = $agent['alias']; } } else { - if ($agent_clean == io_safe_output($agent['nombre'])) { - $agents_item[$agent['id_agente']]['name'] = $agent['nombre']; + if ($agent_clean == io_safe_output($agent['alias'])) { + $agents_item[$agent['id_agente']]['name'] = $agent['alias']; } } } } - if (isset($item['module'])) { + if (isset($item['module']) === true) { $module_clean = str_replace(['[', ']'], '', $item['module']); $regular_expresion = ($module_clean != $item['module']); diff --git a/pandora_console/extras/mr/42.sql b/pandora_console/extras/mr/42.sql index 26f20e0f0a..f4bed54d16 100644 --- a/pandora_console/extras/mr/42.sql +++ b/pandora_console/extras/mr/42.sql @@ -31,4 +31,6 @@ ALTER TABLE `treport` ADD COLUMN `index_render` tinyint(1) NOT NULL DEFAULT 1; ALTER TABLE `treport_template` ADD COLUMN `cover_page_render` tinyint(1) NOT NULL DEFAULT 1; ALTER TABLE `treport_template` ADD COLUMN `index_render` tinyint(1) NOT NULL DEFAULT 1; +UPDATE `tconfig` SET value = '{"0.00000038580247":"Seconds to months","0.00000165343915":"Seconds to weeks","0.00001157407407":"Seconds to days","0.01666666666667":"Seconds to minutes","0.00000000093132":"Bytes to Gigabytes","0.00000095367432":"Bytes to Megabytes","0.00097656250000":"Bytes to Kilobytes","0.00000001653439":"Timeticks to weeks","0.00000011574074":"Timeticks to days"}' WHERE token = 'post_process_custom_values'; + COMMIT; \ No newline at end of file diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index 664a7749e1..b1e8f60aad 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -1405,6 +1405,7 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_incident_type', ''); INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_incident_status', ''); INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_incident_title', ''); INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_incident_content', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('post_process_custom_values', '{"0.00000038580247":"Seconds to months","0.00000165343915":"Seconds to weeks","0.00001157407407":"Seconds to days","0.01666666666667":"Seconds to minutes","0.00000000093132":"Bytes to Gigabytes","0.00000095367432":"Bytes to Megabytes","0.00097656250000":"Bytes to Kilobytes","0.00000001653439":"Timeticks to weeks","0.00000011574074":"Timeticks to days"}'); -- --------------------------------------------------------------------- -- Table `tconfig_os` diff --git a/pandora_console/godmode/events/event_edit_filter.php b/pandora_console/godmode/events/event_edit_filter.php index 56201e3a28..5783797112 100644 --- a/pandora_console/godmode/events/event_edit_filter.php +++ b/pandora_console/godmode/events/event_edit_filter.php @@ -130,6 +130,15 @@ if ($update || $create) { $id_agent = (int) get_parameter('id_agent'); $text_module = get_parameter('text_module', ''); $id_agent_module = (int) get_parameter('module_search_hidden'); + if ($text_module === '') { + $text_module = io_safe_output( + db_get_value_filter( + 'nombre', + 'tagente_modulo', + ['id_agente_modulo' => $id_agent_module] + ) + ); + } $pagination = get_parameter('pagination', ''); $event_view_hr = get_parameter('event_view_hr', ''); $id_user_ack = get_parameter('id_user_ack', ''); diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index 6857a2cd39..a46ee1811e 100755 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -1813,11 +1813,9 @@ switch ($action) { ); $values['id_group'] = get_parameter('combo_group'); - if ($values['server_name'] == '') { - $values['server_name'] = get_parameter( - 'combo_server' - ); - } + $values['server_name'] = get_parameter( + 'combo_server' + ); if ((($values['type'] == 'custom_graph') || ($values['type'] == 'automatic_custom_graph')) @@ -2354,6 +2352,8 @@ switch ($action) { break; } + hd($values['server_name']); + hd(2); if ($values['server_name'] == '') { $values['server_name'] = get_parameter( 'combo_server' diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 230b55a476..4e796c2539 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -114,7 +114,9 @@ if ($get_comments) { sprintf( ' HAVING max_id_evento = %d', $event['id_evento'] - ) + ), + // True for show comments of validated events. + true ); if ($events !== false) { $event = $events[0]; @@ -331,17 +333,52 @@ if ($get_filter_values) { if ($event_filter === false) { $event_filter = [ - 'status' => EVENT_NO_VALIDATED, - 'event_view_hr' => $config['event_view_hr'], - 'group_rep' => 1, - 'tag_with' => [], - 'tag_without' => [], - 'history' => false, + 'status' => EVENT_NO_VALIDATED, + 'event_view_hr' => $config['event_view_hr'], + 'group_rep' => 1, + 'tag_with' => [], + 'tag_without' => [], + 'history' => false, + 'module_search' => '', + 'filter_only_alert' => '-1', + 'user_comment' => '', + 'id_extra' => '', + 'id_user_ack' => '', + 'date_from' => '', + 'date_to' => '', + 'severity' => '', + 'event_type' => '', + 'group_rep' => 0, + 'id_group' => 0, + 'id_group_filter' => 0, + 'group_name' => 'All', + 'text_agent' => '', + 'id_agent' => 0, + 'id_name' => 'None', + 'filter_id' => 0, ]; + } else { + $event_filter['module_search'] = io_safe_output(db_get_value_filter('nombre', 'tagente_modulo', ['id_agente_modulo' => $event_filter['id_agent_module']])); + $a = array_keys(users_get_groups(false)); + $event_filter['group_name'] = ''; + foreach ($a as $key => $value) { + if ($value == $event_filter['id_group']) { + $event_filter['group_name'] = db_get_value('nombre', 'tgrupo', 'id_grupo', $event_filter['id_group_filter']); + if ($event_filter['group_name'] === false) { + $event_filter['group_name'] = __('All'); + } + } + } + + $event_filter['module_search'] = io_safe_output(db_get_value_filter('nombre', 'tagente_modulo', ['id_agente_modulo' => $event_filter['id_agent_module']])); } $event_filter['search'] = io_safe_output($event_filter['search']); $event_filter['id_name'] = io_safe_output($event_filter['id_name']); + $event_filter['text_agent'] = io_safe_output($event_filter['text_agent']); + $event_filter['source'] = io_safe_output($event_filter['source']); + + $event_filter['tag_with'] = base64_encode( io_safe_output($event_filter['tag_with']) ); @@ -353,7 +390,7 @@ if ($get_filter_values) { } if ($load_filter_modal) { - $current = get_parameter('current_filter', ''); + $current = db_get_value_filter('default_event_filter', 'tusuario', ['id_user' => $config['id_user']]); $filters = events_get_event_filter_select(); $user_groups_array = users_get_groups_for_select( $config['id_user'], @@ -433,10 +470,12 @@ function load_form_filter() { }, function (data) { jQuery.each (data, function (i, val) { + console.log(val); if (i == 'id_name') $("#hidden-id_name").val(val); - if (i == 'id_group') - $("#id_group").val(val); + if (i == 'id_group'){ + $('#id_group').val(val); + } if (i == 'event_type') $("#event_type").val(val); if (i == 'severity') { @@ -446,9 +485,9 @@ function load_form_filter() { if (i == 'status') $("#status").val(val); if (i == 'search') - $("#text-search").val(val); + $('#text-search').val(val); if (i == 'text_agent') - $("#text_id_agent").val(val); + $('input[name=text_agent]').val(val); if (i == 'id_agent') $('input:hidden[name=id_agent]').val(val); if (i == 'id_agent_module') @@ -477,6 +516,15 @@ function load_form_filter() { $("#text-user_comment").val(val); if (i == 'id_source_event') $("#text-id_source_event").val(val); + if(i == 'date_from') + $("#text-date_from").val(val); + if(i == 'date_to') + $("#text-date_to").val(val); + if(i == 'module_search') + $('input[name=module_search]').val(val); + if(i == 'group_name') + $("#select2-id_group_filter-container").text(val); + }); reorder_tags_inputs(); // Update the info with the loaded filter @@ -1145,12 +1193,37 @@ if ($change_status) { $event_ids = get_parameter('event_ids'); $new_status = get_parameter('new_status'); - $return = events_change_status(explode(',', $event_ids), $new_status, $meta, $history); + $return = events_change_status( + explode(',', $event_ids), + $new_status, + $meta, + $history + ); - if ($return) { - echo 'status_ok'; + if ($return !== false) { + echo json_encode( + [ + 'status' => 'status_ok', + 'user' => db_get_value( + 'fullname', + 'tusuario', + 'id_user', + $config['id_user'] + ), + ] + ); } else { - echo 'status_error'; + echo json_encode( + [ + 'status' => 'status_error', + 'user' => db_get_value( + 'fullname', + 'tusuario', + 'id_user', + $config['id_user'] + ), + ] + ); } return; diff --git a/pandora_console/include/class/AgentWizard.class.php b/pandora_console/include/class/AgentWizard.class.php index 7f23e84894..e4eb109a57 100644 --- a/pandora_console/include/class/AgentWizard.class.php +++ b/pandora_console/include/class/AgentWizard.class.php @@ -1,4 +1,5 @@ wizardSection === 'snmp_interfaces_explorer') { - // First, try x64 interfaces. - $this->interfacesx64 = true; + // Check if thereis x64 counters. + $snmp_tmp = '.1.3.6.1.2.1.31.1.1.1.6'; + $check_x64 = get_snmpwalk( + $this->targetIp, + $this->version, + $this->community, + $this->authUserV3, + $this->securityLevelV3, + $this->authMethodV3, + $this->authPassV3, + $this->privacyMethodV3, + $this->privacyPassV3, + 0, + $snmp_tmp, + $this->targetPort, + $this->server, + $this->extraArguments + ); + + if ($check_x64) { + $this->interfacesx64 = true; + $oidExplore = '.1.3.6.1.2.1.31.1.1.1.1'; + } else { + $this->interfacesx64 = false; + $oidExplore = '1.3.6.1.2.1.2.2.1.2'; + } + // Explore interface names. $oidExplore = '.1.3.6.1.2.1.31.1.1.1.1'; + $receivedOid = get_snmpwalk( + $this->targetIp, + $this->version, + $this->community, + $this->authUserV3, + $this->securityLevelV3, + $this->authMethodV3, + $this->authPassV3, + $this->privacyMethodV3, + $this->privacyPassV3, + 0, + $oidExplore, + $this->targetPort, + $this->server, + $this->extraArguments + ); } else { // Get the device PEN. $oidExplore = '.1.3.6.1.2.1.1.2.0'; @@ -1310,7 +1351,7 @@ class AgentWizard extends HTML * * @return array */ - public function candidateModuleToCreate(array $data):array + public function candidateModuleToCreate(array $data): array { $modulesActivated = []; $generalInterface = false; @@ -1560,8 +1601,8 @@ class AgentWizard extends HTML if ($this->securityLevelV3 === 'authNoPriv' || $this->securityLevelV3 === 'authPriv' ) { - $values['plugin_parameter'] = $this->authMethodV3; - $values['plugin_pass'] = $this->authPassV3; + $values['plugin_parameter'] = $this->authMethodV3; + $values['plugin_pass'] = $this->authPassV3; if ($this->securityLevelV3 === 'authPriv') { $values['custom_string_1'] = $this->privacyMethodV3; $values['custom_string_2'] = $this->privacyPassV3; @@ -2261,7 +2302,7 @@ class AgentWizard extends HTML private function replacementMacrosPlugin( string $text, array $macros - ):string { + ): string { // Only agents. if (empty($this->idPolicy) === true) { // Common. @@ -2308,7 +2349,7 @@ class AgentWizard extends HTML ?string $value, ?string $unit='', ?int $moduleType=0 - ):string { + ): string { if ($moduleType !== MODULE_TYPE_REMOTE_SNMP_INC && $moduleType !== MODULE_TYPE_GENERIC_DATA_INC && $moduleType !== MODULE_TYPE_REMOTE_TCP_INC @@ -2562,7 +2603,7 @@ class AgentWizard extends HTML // Unpack the extra fields // and include with key field in a field set. $macros = json_decode($module['macros'], true); - $fieldSet = [ '0' => $module['query_key_field'] ]; + $fieldSet = ['0' => $module['query_key_field']]; foreach ($macros as $fieldKey => $fieldMacro) { if (preg_match('/extra_field_/', $fieldKey) !== 0) { $tmpKey = explode('_', $fieldKey); @@ -3100,7 +3141,6 @@ class AgentWizard extends HTML // Add Create Modules form. $this->createModulesForm(); } - } @@ -3209,7 +3249,6 @@ class AgentWizard extends HTML } return false; - } @@ -3306,7 +3345,7 @@ class AgentWizard extends HTML * * @return array Inputs for common data. */ - private function getCommonDataInputs():array + private function getCommonDataInputs(): array { $inputs[] = [ 'id' => 'create-modules-action', @@ -4116,13 +4155,13 @@ class AgentWizard extends HTML } - /** - * This function return the definition of modules for SNMP Interfaces - * - * @param array $data Data. - * - * @return array Return modules for defect. - */ + /** + * This function return the definition of modules for SNMP Interfaces + * + * @param array $data Data. + * + * @return array Return modules for defect. + */ private function getInterfacesModules(array $data=[]) { $moduleDescription = ''; @@ -4207,6 +4246,34 @@ class AgentWizard extends HTML ], ]; + // Get x86 or x64 modules. + if ($this->interfacesx64 === true) { + $definition_temp = $this->getInterfacesModulesx64($data); + } else { + $definition_temp = $this->getInterfacesModulesx86($data); + } + + // General monitoring names. + $general_module_names = [ + 'ifInOctets / ifHCInOctets', + 'ifOutOctets / ifHCOutOctets', + 'ifInUcastPkts / ifHCInUcastPkts', + 'ifOutUcastPkts / ifHCOutUcastPkts', + 'ifInNUcastPkts / ifHCInNUcastPkts', + 'ifOutNUcastPkts / ifHCOutNUcastPkts', + ]; + + if ($name == '') { + foreach ($definition_temp as $module => $module_def) { + $definition_temp[$module]['module_name'] = array_shift($general_module_names); + } + } + + if (empty($definition_temp) === false) { + $definition = array_merge($definition, $definition_temp); + } + + // Continue with common x86 and x84 modules. // IfAdminStatus. $moduleName = $name.'ifAdminStatus'; $definition['ifAdminStatus'] = [ @@ -4333,19 +4400,6 @@ class AgentWizard extends HTML ], ]; - // Get x86 or x64 modules. - if ($this->interfacesx64 === true) { - $definitionx64 = $this->getInterfacesModulesx64($data); - if (empty($definitionx64) === false) { - $definition = array_merge($definition, $definitionx64); - } - } else { - $definitionx86 = $this->getInterfacesModulesx86($data); - if (empty($definitionx86) === false) { - $definition = array_merge($definition, $definitionx86); - } - } - return $definition; } @@ -4815,7 +4869,7 @@ class AgentWizard extends HTML try { exec($execution, $output); } catch (Exception $ex) { - $output = [ '0' => 'ERROR: Failed execution: '.(string) $ex]; + $output = ['0' => 'ERROR: Failed execution: '.(string) $ex]; } return $output; @@ -4913,7 +4967,7 @@ class AgentWizard extends HTML // Meta. var meta = ""; var hack_meta = ''; - if(meta){ + if (meta) { hack_meta = '../../'; } @@ -4921,15 +4975,15 @@ class AgentWizard extends HTML showV3Form(); // Filter search interfaces snmp. - $('#text-filter-search').keyup(function () { + $('#text-filter-search').keyup(function() { var string = $('#text-filter-search').val(); var regex = new RegExp(string); var interfaces = $('.interfaces_search'); - interfaces.each(function(){ - if(string == ''){ + interfaces.each(function() { + if (string == '') { $(this).removeClass('hidden'); } else { - if(this.id.match(regex)) { + if (this.id.match(regex)) { $(this).removeClass('hidden'); } else { $(this).addClass('hidden'); @@ -4939,12 +4993,12 @@ class AgentWizard extends HTML }); // Loading. - $('#submit-sub-protocol').click(function () { + $('#submit-sub-protocol').click(function() { $('.wizard-result').remove(); $('#form-create-modules').remove(); $('.textodialogo').remove(); $('.loading-wizard') - .html('
Loading...
'); + .html('
Loading...
'); }); }); @@ -4962,17 +5016,17 @@ class AgentWizard extends HTML function showSecurityLevelForm() { var selector = $('#securityLevelV3').val(); - if(selector === 'authNoPriv' || selector === 'authPriv'){ + if (selector === 'authNoPriv' || selector === 'authPriv') { $('#txt-authMethodV3').removeClass('invisible'); $('#txt-authPassV3').removeClass('invisible'); - if(selector === 'authPriv'){ + if (selector === 'authPriv') { $('#txt-privacyMethodV3').removeClass('invisible'); $('#txt-privacyPassV3').removeClass('invisible'); } else { $('#txt-privacyMethodV3').addClass('invisible'); $('#txt-privacyPassV3').addClass('invisible'); } - } else { + } else { $('#txt-authMethodV3').addClass('invisible'); $('#txt-authPassV3').addClass('invisible'); $('#txt-privacyMethodV3').addClass('invisible'); @@ -4986,45 +5040,42 @@ class AgentWizard extends HTML var text = ""; var failed = 0; try { - data = JSON.parse(data); - text = data["result"]; + data = JSON.parse(data); + text = data["result"]; } catch (err) { - title = ""; - text = err.message; - failed = 1; + title = ""; + text = err.message; + failed = 1; } if (!failed && data["error"] != undefined) { - title = ""; - text = data["error"]; - failed = 1; + title = ""; + text = data["error"]; + failed = 1; } if (data["report"] != undefined) { - data["report"].forEach(function(item) { - text += "
" + item; - }); + data["report"].forEach(function(item) { + text += "
" + item; + }); } $("#msg").empty(); $("#msg").html(text); $("#msg").dialog({ - width: 450, - position: { - my: "center", - at: "center", - of: window, - collision: "fit" - }, - title: title, - buttons: [ - { - class: - "ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next", + width: 450, + position: { + my: "center", + at: "center", + of: window, + collision: "fit" + }, + title: title, + buttons: [{ + class: "ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next", text: "OK", click: function(e) { $("#msg").close(); } - } - ] + }] }); } @@ -5044,8 +5095,8 @@ class AgentWizard extends HTML var markedCount = 0; if (type == 'block') { selectedBlock - .parent() - .removeClass("alpha50"); + .parent() + .removeClass("alpha50"); if (selectedBlock.prop("checked")) { // Set to active the values of fields. $("[id*=hidden-module-active-"+blockNumber+"]") @@ -5054,9 +5105,9 @@ class AgentWizard extends HTML }); // Set checked. $("[id*=checkbox-sel_module_" + blockNumber + "]") - .each(function(){ - $(this).prop("checked", true); - }); + .each(function() { + $(this).prop("checked", true); + }); imageInfoModules.removeClass('hidden'); } else { // Set to inactive the values of fields. @@ -5066,15 +5117,15 @@ class AgentWizard extends HTML }); // Set unchecked. $("[id*=checkbox-sel_module_" + blockNumber + "]") - .each(function(){ - $(this).prop("checked", false); - }); + .each(function() { + $(this).prop("checked", false); + }); imageInfoModules.addClass('hidden'); } } else if (type == 'module') { // Getting the element. - var thisModuleHidden = document.getElementById("hidden-module-active-"+switchName[2]+"_"+moduleNumber); - var thisModule = $("#checkbox-sel_module_"+blockNumber+"_"+moduleNumber); + var thisModuleHidden = document.getElementById("hidden-module-active-" + switchName[2] + "_" + moduleNumber); + var thisModule = $("#checkbox-sel_module_" + blockNumber + "_" + moduleNumber); // Setting the individual field if (thisModule.prop('checked')) { thisModuleHidden.value = '1'; @@ -5084,12 +5135,12 @@ class AgentWizard extends HTML // Get the list of selected modules. $("[id*=checkbox-sel_module_" + blockNumber + "]") - .each(function() { - if ($(this).prop("checked")) { - markedCount++; - } - totalCount++; - }); + .each(function() { + if ($(this).prop("checked")) { + markedCount++; + } + totalCount++; + }); if (totalCount == markedCount) { selectedBlock.prop("checked", true); @@ -5118,7 +5169,7 @@ class AgentWizard extends HTML */ function switchBlockControlInterfaces(e) { var string = $('#text-filter-search').val(); - if(string == ''){ + if (string == '') { if (e.checked) { $(".interfaz_select").prop("checked", true); } else { @@ -5127,15 +5178,15 @@ class AgentWizard extends HTML } else { var regex = new RegExp(string); var interfaces = $('.interfaces_search'); - interfaces.each(function(){ - if(this.id.match(regex)) { + interfaces.each(function() { + if (this.id.match(regex)) { $(this).removeClass('hidden'); if (e.checked) { - $("input[name='interfaz_select_"+this.id+"']") + $("input[name='interfaz_select_" + this.id + "']") .prop("checked", true); } else { - $("input[name='interfaz_select_"+this.id+"']") - .prop("checked", false); + $("input[name='interfaz_select_" + this.id + "']") + .prop("checked", false); } } }); @@ -5143,13 +5194,13 @@ class AgentWizard extends HTML } /** - * Show the modal with modules for create. - */ + * Show the modal with modules for create. + */ function processListModules() { confirmDialog({ title: "", message: function() { - var id = "div-"+uniqId(); + var id = "div-" + uniqId(); var loading = "" + "..."; $.ajax({ method: "post", @@ -5165,22 +5216,22 @@ class AgentWizard extends HTML }, datatype: "html", success: function(data) { - $('#'+id).empty().append(data); + $('#' + id).empty().append(data); }, error: function(e) { showMsg(e); } }); - return "
"+loading+"
"; + return "
" + loading + "
"; }, ok: "", cancel: "", onAccept: function() { - $('#reviewed-modules').submit(); + $('#reviewed-modules').submit(); }, - size:750, - maxHeight:500 + size: 750, + maxHeight: 500 }); } diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index e490b8d671..602e73e968 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -20,7 +20,7 @@ /** * Pandora build version and version */ -$build_version = 'PC201029'; +$build_version = 'PC201103'; $pandora_version = 'v7.0NG.750'; // Do not overwrite default timezone set if defined. diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 2566e265be..74a024d866 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -2871,17 +2871,8 @@ function alerts_get_agent_modules( ); $agent_modules = db_get_all_rows_sql($sql); } else { - $groups = groups_get_children($id_grupo, true); + $groups = groups_get_children_ids($id_grupo, true); if (empty($groups) === false) { - $groups = array_reduce( - $groups, - function ($carry, $item) { - $carry[] = $item['id_grupo']; - return $carry; - }, - [$id_grupo] - ); - $sql = sprintf( 'SELECT distinct(atm.id_agent_module) FROM talert_template_modules atm diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 7b598f7ab2..33c2309e30 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -673,15 +673,16 @@ function events_update_status($id_evento, $status, $filter=null, $history=false) /** * Retrieve all events filtered. * - * @param array $fields Fields to retrieve. - * @param array $filter Filters to be applied. - * @param integer $offset Offset (pagination). - * @param integer $limit Limit (pagination). - * @param string $order Sort order. - * @param string $sort_field Sort field. - * @param boolean $history Apply on historical table. - * @param boolean $return_sql Return SQL (true) or execute it (false). - * @param string $having Having filter. + * @param array $fields Fields to retrieve. + * @param array $filter Filters to be applied. + * @param integer $offset Offset (pagination). + * @param integer $limit Limit (pagination). + * @param string $order Sort order. + * @param string $sort_field Sort field. + * @param boolean $history Apply on historical table. + * @param boolean $return_sql Return SQL (true) or execute it (false). + * @param string $having Having filter. + * @param boolean $validatedEvents If true, evaluate validated events. * * @return array Events. * @throws Exception On error. @@ -695,7 +696,8 @@ function events_get_all( $sort_field=null, $history=false, $return_sql=false, - $having='' + $having='', + $validatedEvents=false ) { global $config; @@ -912,10 +914,20 @@ function events_get_all( break; case EVENT_NO_VALIDATED: + // Show comments in validated events. + $validatedState = ''; + if ($validatedEvents === true) { + $validatedState = sprintf( + 'OR estado = %d', + EVENT_VALIDATE + ); + } + $sql_filters[] = sprintf( - ' AND (estado = %d OR estado = %d)', + ' AND (estado = %d OR estado = %d %s)', EVENT_NEW, - EVENT_PROCESS + EVENT_PROCESS, + $validatedState ); break; } @@ -1540,26 +1552,18 @@ function events_get_event($id, $fields=false, $meta=false, $history=false) /** * Retrieve all events ungrouped. * - * @param string $sql_post Sql_post. - * @param integer $offset Offset. - * @param integer $pagination Pagination. - * @param boolean $meta Meta. - * @param boolean $history History. - * @param boolean $total Total. - * @param boolean $history_db History_db. - * @param string $order Order. + * @param string $sql_post Sql_post. + * @param boolean $meta Meta. + * @param boolean $history History. + * @param boolean $returnSql Only Query. * * @return mixed Array of events or false. */ function events_get_events_no_grouped( $sql_post, - $offset=0, - $pagination=1, $meta=false, $history=false, - $total=false, - $history_db=false, - $order='ASC' + $returnSql=false ) { global $config; @@ -1569,7 +1573,11 @@ function events_get_events_no_grouped( $sql .= events_get_secondary_groups_left_join($table); $sql .= $sql_post; - $events = db_get_all_rows_sql($sql, $history_db); + if ($returnSql === true) { + return $sql; + } + + $events = db_get_all_rows_sql($sql, $history); return $events; } @@ -1622,29 +1630,59 @@ function events_get_events_grouped( $event_lj = events_get_secondary_groups_left_join($table); if ($total) { $sql = "SELECT COUNT(*) FROM (SELECT id_evento - FROM $table te $event_lj - WHERE 1=1 ".$sql_post.' + FROM $table te $event_lj ".$sql_post.' GROUP BY estado, evento, id_agente, id_agentmodule'.$groupby_extra.') AS t'; } else { - $sql = "SELECT *, MAX(id_evento) AS id_evento, - GROUP_CONCAT(DISTINCT user_comment SEPARATOR '
') AS user_comment, - GROUP_CONCAT(DISTINCT id_evento SEPARATOR ',') AS similar_ids, - COUNT(id_evento) AS event_rep, MAX(utimestamp) AS timestamp_rep, - MIN(utimestamp) AS timestamp_rep_min, - (SELECT owner_user FROM $table WHERE id_evento = MAX(te.id_evento)) owner_user, - (SELECT id_usuario FROM $table WHERE id_evento = MAX(te.id_evento)) id_usuario, - (SELECT id_agente FROM $table WHERE id_evento = MAX(te.id_evento)) id_agente, - (SELECT criticity FROM $table WHERE id_evento = MAX(te.id_evento)) AS criticity, - (SELECT ack_utimestamp FROM $table WHERE id_evento = MAX(te.id_evento)) AS ack_utimestamp, - (SELECT nombre FROM tagente_modulo WHERE id_agente_modulo = te.id_agentmodule) AS module_name - FROM $table te $event_lj - WHERE 1=1 ".$sql_post.' - GROUP BY estado, evento, id_agente, id_agentmodule'.$groupby_extra; - $sql .= ' '.events_get_sql_order($sort_field, $order, 2); - $sql .= ' LIMIT '.$offset.','.$pagination; + $sql = sprintf( + 'SELECT *, + MAX(id_evento) AS id_evento, + GROUP_CONCAT( + DISTINCT user_comment SEPARATOR "
" + ) AS user_comment, + GROUP_CONCAT( + DISTINCT id_evento SEPARATOR "," + ) AS similar_ids, + COUNT(id_evento) AS event_rep, MAX(utimestamp) AS timestamp_rep, + MIN(utimestamp) AS timestamp_rep_min, + (SELECT owner_user + FROM %s + WHERE id_evento = MAX(te.id_evento)) AS owner_user, + (SELECT id_usuario + FROM %s + WHERE id_evento = MAX(te.id_evento)) AS id_usuario, + (SELECT id_agente + FROM %s + WHERE id_evento = MAX(te.id_evento)) AS id_agente, + (SELECT criticity + FROM %s + WHERE id_evento = MAX(te.id_evento)) AS criticity, + (SELECT ack_utimestamp + FROM %s + WHERE id_evento = MAX(te.id_evento)) AS ack_utimestamp, + (SELECT nombre + FROM tagente_modulo + WHERE id_agente_modulo = te.id_agentmodule) AS module_name + FROM %s te %s + %s + GROUP BY estado, evento, id_agente, id_agentmodule %s + %s + LIMIT %d, %d', + $table, + $table, + $table, + $table, + $table, + $table, + $event_lj, + $sql_post, + $groupby_extra, + events_get_sql_order($sort_field, $order, 2), + $offset, + $pagination + ); } - // Extract the events by filter (or not) from db + // Extract the events by filter (or not) from db. $events = db_get_all_rows_sql($sql, $history_db); if ($total) { @@ -2959,7 +2997,8 @@ function events_get_agent( $type = []; foreach ($filter_event_type as $event_type) { if ($event_type != '') { - // If normal, warning, could be several (going_up_warning, going_down_warning... too complex. + // If normal, warning, could be several + // (going_up_warning, going_down_warning... too complex. // Shown to user only "warning, critical and normal". if ($event_type == 'warning' || $event_type == 'critical' || $event_type == 'normal') { $type[] = " event_type LIKE '%".$event_type."%' "; @@ -2979,10 +3018,10 @@ function events_get_agent( } if ($events_group) { - $sql_where .= sprintf( + $secondary_groups = sprintf( ' INNER JOIN tgrupo tg - ON (te.id_grupo = tg.id_grupo AND tg.id_grupo = %s) - OR (tg.id_grupo = tasg.id_group AND tasg.id_group = %s) + ON (te.id_grupo = tg.id_grupo AND tg.id_grupo IN (%s)) + OR (tg.id_grupo = tasg.id_group AND tasg.id_group IN (%s)) WHERE utimestamp > %d AND utimestamp <= %d ', join(',', $id_group), @@ -2990,22 +3029,27 @@ function events_get_agent( $datelimit, $date ); - } else if ($events_module) { - $sql_where .= sprintf( - ' AND id_agentmodule = %d AND utimestamp > %d - AND utimestamp <= %d ', - $id_agent_module, - $datelimit, - $date - ); + $sql_where = $secondary_groups.' '.$sql_where; } else { - $sql_where .= sprintf( - ' AND id_agente = %d AND utimestamp > %d - AND utimestamp <= %d ', - $id_agent, - $datelimit, - $date - ); + $sql_where = ' WHERE 1=1 '.$sql_where; + + if ($events_module) { + $sql_where .= sprintf( + ' AND id_agentmodule = %d AND utimestamp > %d + AND utimestamp <= %d ', + $id_agent_module, + $datelimit, + $date + ); + } else { + $sql_where .= sprintf( + ' AND id_agente = %d AND utimestamp > %d + AND utimestamp <= %d ', + $id_agent, + $datelimit, + $date + ); + } } if (is_metaconsole() && $id_server) { @@ -3025,11 +3069,7 @@ function events_get_agent( } else { return events_get_events_no_grouped( $sql_where, - 0, - 1000, (is_metaconsole() && $id_server) ? true : false, - false, - false, $history ); } @@ -3682,6 +3722,38 @@ function events_get_response_target( $event_response = db_get_row('tevent_response', 'id', $response_id); $target = io_safe_output($event_response['target']); + if (strpos($target, '_agent_alias_') !== false) { + if ($meta) { + $agente_table_name = 'tmetaconsole_agent'; + $filter = [ + 'id_tagente' => $event['id_agente'], + 'id_tmetaconsole_setup' => $server_id, + ]; + } else { + $agente_table_name = 'tagente'; + $filter = ['id_agente' => $event['id_agente']]; + } + + $alias = db_get_value_filter('alias', $agente_table_name, $filter); + $target = str_replace('_agent_alias_', io_safe_output($alias), $target); + } + + if (strpos($target, '_agent_name_') !== false) { + if ($meta) { + $agente_table_name = 'tmetaconsole_agent'; + $filter = [ + 'id_tagente' => $event['id_agente'], + 'id_tmetaconsole_setup' => $server_id, + ]; + } else { + $agente_table_name = 'tagente'; + $filter = ['id_agente' => $event['id_agente']]; + } + + $name = db_get_value_filter('nombre', $agente_table_name, $filter); + $target = str_replace('_agent_name_', io_safe_output($name), $target); + } + // Substitute each macro. if (strpos($target, '_agent_address_') !== false) { if ($meta) { @@ -3761,7 +3833,7 @@ function events_get_response_target( if (strpos($target, '_group_name_') !== false) { $target = str_replace( '_group_name_', - groups_get_name($event['id_grupo'], true), + io_safe_output(groups_get_name($event['id_grupo'], true)), $target ); } @@ -3777,7 +3849,7 @@ function events_get_response_target( if (strpos($target, '_event_date_') !== false) { $target = str_replace( '_event_date_', - date($config['date_format'], $event['utimestamp']), + io_safe_output(date($config['date_format'], $event['utimestamp'])), $target ); } @@ -3801,7 +3873,7 @@ function events_get_response_target( if (strpos($target, '_alert_id_') !== false) { $target = str_replace( '_alert_id_', - empty($event['is_alert_am']) ? __('N/A') : $event['is_alert_am'], + empty($event['id_alert_am']) ? __('N/A') : $event['id_alert_am'], $target ); } @@ -3883,6 +3955,15 @@ function events_get_response_target( $target = str_replace('_current_user_', $config['id_user'], $target); } + // This will replace the macro with the command timeout value. + if (strpos($target, '_command_timeout_') !== false) { + $target = str_replace( + '_command_timeout_', + $event_response['command_timeout'], + $target + ); + } + return $target; } @@ -4620,16 +4701,24 @@ function events_page_general($event) $table_general->data[] = $data; // If event is validated, show who and when acknowleded it. + $table_general->cellclass[8][1] = 'general_acknowleded'; + $data = []; $data[0] = __('Acknowledged by'); if ($event['estado'] == 1) { - $user_ack = db_get_value('fullname', 'tusuario', 'id_user', $event['id_usuario']); - if (empty($user_ack)) { + $user_ack = db_get_value( + 'fullname', + 'tusuario', + 'id_user', + $event['id_usuario'] + ); + + if (empty($user_ack) === true) { $user_ack = $event['id_usuario']; } - $date_ack = date($config['date_format'], $event['ack_utimestamp']); + $date_ack = io_safe_output($event['ack_utimestamp']); $data[1] = $user_ack.' ('.$date_ack.')'; } else { $data[1] = ''.__('N/A').''; @@ -6963,7 +7052,7 @@ function events_get_field_value_by_event_id( if (strpos($value, '_group_name_') !== false) { $value = str_replace( '_group_name_', - groups_get_name($event['id_grupo'], true), + io_safe_output(groups_get_name($event['id_grupo'], true)), $value ); } @@ -6979,7 +7068,9 @@ function events_get_field_value_by_event_id( if (strpos($value, '_event_date_') !== false) { $value = str_replace( '_event_date_', - date($config['date_format'], $event['utimestamp']), + io_safe_output( + date($config['date_format'], $event['utimestamp']) + ), $value ); } diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 4fd1439f8f..f40b75e3b2 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -2541,13 +2541,9 @@ function graphic_agentaccess( } else { $options['generals']['pdf']['width'] = 350; $options['generals']['pdf']['height'] = 125; - if (!empty($data_array)) { - $imgbase64 = ''; - } else { - $imgbase64 .= vbar_graph($data_array, $options, 2); - } + $imgbase64 = ''; return $imgbase64; } diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 539bc46dc6..479adc67c8 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -2957,7 +2957,7 @@ function reporting_group_report($report, $content) if (empty($id_group)) { $events = []; } else { - $sql_where = sprintf(' AND id_grupo IN (%s) AND estado<>1 ', implode(',', $id_group)); + $sql_where = sprintf(' WHERE id_grupo IN (%s) AND estado<>1 ', implode(',', $id_group)); $events = events_get_events_grouped( $sql_where, 0, diff --git a/pandora_console/include/functions_treeview.php b/pandora_console/include/functions_treeview.php index 25e0f67020..67bed22be3 100755 --- a/pandora_console/include/functions_treeview.php +++ b/pandora_console/include/functions_treeview.php @@ -802,7 +802,7 @@ function treeview_printTable($id_agente, $server_data=[], $no_head=false) $events_graph = '
'; $events_graph .= graph_graphic_agentevents( $id_agente, - '385px;', + '340px;margin:0', 45, SECONDS_1DAY, '', diff --git a/pandora_console/include/graphs/flot/jquery.flot.exportdata.pandora.js b/pandora_console/include/graphs/flot/jquery.flot.exportdata.pandora.js index 6466a72835..47b8879ace 100644 --- a/pandora_console/include/graphs/flot/jquery.flot.exportdata.pandora.js +++ b/pandora_console/include/graphs/flot/jquery.flot.exportdata.pandora.js @@ -1,425 +1,424 @@ -(function ($) { - var options = { - export: { - export_data: false, // or true - labels_long: null, - homeurl: "", - }, - }; +(function($) { + var options = { + export: { + export_data: false, // or true + labels_long: null, + homeurl: "" + } + }; - function init(plot) { - plot.exportDataCSV = function (args) { - //amount = plot.getOptions().export.type, - //options = options || {}; + function init(plot) { + plot.exportDataCSV = function(args) { + //amount = plot.getOptions().export.type, + //options = options || {}; - // Options - var type = "csv"; - type = type.toLowerCase().trim(); + // Options + var type = "csv"; + type = type.toLowerCase().trim(); - var graphData, - dataObject, - dataObjects = plot.getData(), - result = []; + var graphData, + dataObject, + dataObjects = plot.getData(), + result = []; - // Throw errors - var retrieveDataOject = function (dataObjects) { - var result; + // Throw errors + var retrieveDataOject = function(dataObjects) { + var result; - if (typeof dataObjects === "undefined") - throw new Error("Empty parameter"); + if (typeof dataObjects === "undefined") + throw new Error("Empty parameter"); - // Try to retrieve the avg set (not 100% reliable, I know) - if (dataObjects.length == 1) { - result = dataObjects.shift(); - } - if (dataObjects.length > 1) { - dataObjects.forEach(function (element) { - if (/^Avg.:/i.test(element.label)) result = element; - }); + // Try to retrieve the avg set (not 100% reliable, I know) + if (dataObjects.length == 1) { + result = dataObjects.shift(); + } + if (dataObjects.length > 1) { + dataObjects.forEach(function(element) { + if (/^Avg.:/i.test(element.label)) result = element; + }); - // If the avg set is missing, retrieve the first set - if (typeof result === "undefined") result = dataObjects.shift(); - } + // If the avg set is missing, retrieve the first set + if (typeof result === "undefined") result = dataObjects.shift(); + } - if (typeof result === "undefined") throw new Error("Empty result"); + if (typeof result === "undefined") throw new Error("Empty result"); - return result; - }; + return result; + }; - // Throw errors - var processDataObject = function (dataObject) { - var result; + // Throw errors + var processDataObject = function(dataObject) { + var result; - if (typeof dataObject === "undefined") - throw new Error("Empty parameter"); + if (typeof dataObject === "undefined") + throw new Error("Empty parameter"); - if ( - typeof dataObject.data === "undefined" || - !(dataObject.data instanceof Array) - ) - throw new Error("Object malformed"); + if ( + typeof dataObject.data === "undefined" || + !(dataObject.data instanceof Array) + ) + throw new Error("Object malformed"); - /* { - * head: [,,...,], - * data: [ - * [,,...,], - * [,,...,], - * ..., - * [,,...,], - * ] - * } - */ - if (type === "csv") { - result = { - head: ["timestap", "date", "value", "label"], - data: [], - }; + /* { + * head: [,,...,], + * data: [ + * [,,...,], + * [,,...,], + * ..., + * [,,...,], + * ] + * } + */ + if (type === "csv") { + result = { + head: ["timestamp", "date", "value", "label"], + data: [] + }; - dataObject.data.forEach(function (item, index) { - var timestap = item[0]; + dataObject.data.forEach(function(item, index) { + var timestamp = item[0]; - var d = new Date(item[0]); - var monthNames = [ - "Jan", - "Feb", - "Mar", - "Apr", - "May", - "Jun", - "Jul", - "Aug", - "Sep", - "Oct", - "Nov", - "Dec", - ]; + var d = new Date(item[0]); + var monthNames = [ + "Jan", + "Feb", + "Mar", + "Apr", + "May", + "Jun", + "Jul", + "Aug", + "Sep", + "Oct", + "Nov", + "Dec" + ]; - date_format = - (d.getDate() < 10 ? "0" : "") + - d.getDate() + - " " + - monthNames[d.getMonth()] + - " " + - d.getFullYear() + - " " + - (d.getHours() < 10 ? "0" : "") + - d.getHours() + - ":" + - (d.getMinutes() < 10 ? "0" : "") + - d.getMinutes() + - ":" + - (d.getSeconds() < 10 ? "0" : "") + - d.getSeconds(); + date_format = + (d.getDate() < 10 ? "0" : "") + + d.getDate() + + " " + + monthNames[d.getMonth()] + + " " + + d.getFullYear() + + " " + + (d.getHours() < 10 ? "0" : "") + + d.getHours() + + ":" + + (d.getMinutes() < 10 ? "0" : "") + + d.getMinutes() + + ":" + + (d.getSeconds() < 10 ? "0" : "") + + d.getSeconds(); - var date = date_format; + var date = date_format; - var value = item[1]; + var value = item[1]; - var clean_label = plot.getOptions().export.labels_long[ - dataObject.label - ]; - clean_label = clean_label.replace(new RegExp(" ", "g"), " "); - result.data.push([timestap, date, value, clean_label]); - }); - } else if (type === "json") { - /* [ - * { - * 'date': , - * 'value': - * } - * ], - * [ - * { - * 'date': , - * 'value': - * } - * ], - * ..., - * [ - * { - * 'date': , - * 'value': - * } - * ] - */ - result = []; + var clean_label = plot.getOptions().export.labels_long[ + dataObject.label + ]; + clean_label = clean_label.replace(new RegExp(" ", "g"), " "); + result.data.push([timestamp, date, value, clean_label]); + }); + } else if (type === "json") { + /* [ + * { + * 'date': , + * 'value': + * } + * ], + * [ + * { + * 'date': , + * 'value': + * } + * ], + * ..., + * [ + * { + * 'date': , + * 'value': + * } + * ] + */ + result = []; - dataObject.data.forEach(function (item, index) { - var date = "", - value = item[1]; + dataObject.data.forEach(function(item, index) { + var date = "", + value = item[1]; - // Long labels are preferred - if (typeof labels_long[index] !== "undefined") - date = labels_long[index]; - else if (typeof labels[index] !== "undefined") date = labels[index]; + // Long labels are preferred + if (typeof labels_long[index] !== "undefined") + date = labels_long[index]; + else if (typeof labels[index] !== "undefined") date = labels[index]; - result.push({ - date: date, - value: value, - label: dataObject.label, - }); - }); - } + result.push({ + date: date, + value: value, + label: dataObject.label + }); + }); + } - if (typeof result === "undefined") throw new Error("Empty result"); + if (typeof result === "undefined") throw new Error("Empty result"); - return result; - }; + return result; + }; - try { - var elements = []; - dataObject = retrieveDataOject(dataObjects); - if (dataObject) { - elements.push(processDataObject(dataObject)); - } - dataObjects.forEach(function (element) { - elements.push(processDataObject(element)); - }); - graphData = elements; + try { + var elements = []; + dataObject = retrieveDataOject(dataObjects); + if (dataObject) { + elements.push(processDataObject(dataObject)); + } + dataObjects.forEach(function(element) { + elements.push(processDataObject(element)); + }); + graphData = elements; + // Transform the object data into a string + // cause PHP has limitations in the number + // of POST params received. + var graphDataStr = JSON.stringify(graphData); - // Transform the object data into a string - // cause PHP has limitations in the number - // of POST params received. - var graphDataStr = JSON.stringify(graphData); + // Build form + var $form = $("
"), + $dataInput = $(""), + $typeInput = $(""), + $separatorInput = $(""), + $excelInput = $(""); - // Build form - var $form = $("
"), - $dataInput = $(""), - $typeInput = $(""), - $separatorInput = $(""), - $excelInput = $(""); + $dataInput + .prop("name", "data") + .prop("type", "text") + .prop("value", graphDataStr); - $dataInput - .prop("name", "data") - .prop("type", "text") - .prop("value", graphDataStr); + $typeInput + .prop("name", "type") + .prop("type", "text") + .prop("value", type); - $typeInput - .prop("name", "type") - .prop("type", "text") - .prop("value", type); + $separatorInput + .prop("name", "separator") + .prop("type", "text") + .prop("value", ";"); - $separatorInput - .prop("name", "separator") - .prop("type", "text") - .prop("value", ";"); + $excelInput + .prop("name", "excel_encoding") + .prop("type", "text") + .prop("value", 0); - $excelInput - .prop("name", "excel_encoding") - .prop("type", "text") - .prop("value", 0); + $form + .prop("method", "POST") + .prop( + "action", + plot.getOptions().export.homeurl + "include/graphs/export_data.php" + ) + .append($dataInput, $typeInput, $separatorInput, $excelInput) + .hide() + // Firefox made me write into the DOM for this :( + .appendTo("body") + .submit(); + } catch (e) { + alert("There was an error exporting the data"); + } + }; - $form - .prop("method", "POST") - .prop( - "action", - plot.getOptions().export.homeurl + "include/graphs/export_data.php" - ) - .append($dataInput, $typeInput, $separatorInput, $excelInput) - .hide() - // Firefox made me write into the DOM for this :( - .appendTo("body") - .submit(); - } catch (e) { - alert("There was an error exporting the data"); - } - }; + plot.exportDataJSON = function(args) { + //amount = plot.getOptions().export.type, + //options = options || {}; - plot.exportDataJSON = function (args) { - //amount = plot.getOptions().export.type, - //options = options || {}; + // Options + var type = "json"; + type = type.toLowerCase().trim(); - // Options - var type = "json"; - type = type.toLowerCase().trim(); + var graphData, + dataObject, + dataObjects = plot.getData(), + result = []; - var graphData, - dataObject, - dataObjects = plot.getData(), - result = []; + // Throw errors + var retrieveDataOject = function(dataObjects) { + var result; - // Throw errors - var retrieveDataOject = function (dataObjects) { - var result; + if (typeof dataObjects === "undefined") + throw new Error("Empty parameter"); - if (typeof dataObjects === "undefined") - throw new Error("Empty parameter"); + // Try to retrieve the avg set (not 100% reliable, I know) + if (dataObjects.length == 1) { + result = dataObjects.shift(); + } + if (dataObjects.length > 1) { + dataObjects.forEach(function(element) { + if (/^Avg.:/i.test(element.label)) result = element; + }); - // Try to retrieve the avg set (not 100% reliable, I know) - if (dataObjects.length == 1) { - result = dataObjects.shift(); - } - if (dataObjects.length > 1) { - dataObjects.forEach(function (element) { - if (/^Avg.:/i.test(element.label)) result = element; - }); + // If the avg set is missing, retrieve the first set + if (typeof result === "undefined") result = dataObjects.shift(); + } - // If the avg set is missing, retrieve the first set - if (typeof result === "undefined") result = dataObjects.shift(); - } + if (typeof result === "undefined") throw new Error("Empty result"); - if (typeof result === "undefined") throw new Error("Empty result"); + return result; + }; - return result; - }; + // Throw errors + var processDataObject = function(dataObject) { + var result; - // Throw errors - var processDataObject = function (dataObject) { - var result; + if (typeof dataObject === "undefined") + throw new Error("Empty parameter"); - if (typeof dataObject === "undefined") - throw new Error("Empty parameter"); + if ( + typeof dataObject.data === "undefined" || + !(dataObject.data instanceof Array) + ) + throw new Error("Object malformed"); - if ( - typeof dataObject.data === "undefined" || - !(dataObject.data instanceof Array) - ) - throw new Error("Object malformed"); + /* { + * head: [,,...,], + * data: [ + * [,,...,], + * [,,...,], + * ..., + * [,,...,], + * ] + * } + */ + if (type === "csv") { + result = { + head: ["date", "value", "label"], + data: [] + }; - /* { - * head: [,,...,], - * data: [ - * [,,...,], - * [,,...,], - * ..., - * [,,...,], - * ] - * } - */ - if (type === "csv") { - result = { - head: ["date", "value", "label"], - data: [], - }; + dataObject.data.forEach(function(item, index) { + var date = "", + value = item[1]; - dataObject.data.forEach(function (item, index) { - var date = "", - value = item[1]; + // Long labels are preferred + if ( + typeof plot.getOptions().export.labels_long[index] !== "undefined" + ) + date = plot.getOptions().export.labels_long[index]; + else if (typeof labels[index] !== "undefined") date = labels[index]; - // Long labels are preferred - if ( - typeof plot.getOptions().export.labels_long[index] !== "undefined" - ) - date = plot.getOptions().export.labels_long[index]; - else if (typeof labels[index] !== "undefined") date = labels[index]; + result.data.push([date, value, dataObject.label]); + }); + } else if (type === "json") { + /* [ + * { + * 'date': , + * 'value': + * } + * ], + * [ + * { + * 'date': , + * 'value': + * } + * ], + * ..., + * [ + * { + * 'date': , + * 'value': + * } + * ] + */ + result = []; - result.data.push([date, value, dataObject.label]); - }); - } else if (type === "json") { - /* [ - * { - * 'date': , - * 'value': - * } - * ], - * [ - * { - * 'date': , - * 'value': - * } - * ], - * ..., - * [ - * { - * 'date': , - * 'value': - * } - * ] - */ - result = []; + dataObject.data.forEach(function(item, index) { + var date = "", + value = item[1]; - dataObject.data.forEach(function (item, index) { - var date = "", - value = item[1]; + // Long labels are preferred + if (typeof labels_long[index] !== "undefined") + date = labels_long[index]; + else if (typeof labels[index] !== "undefined") date = labels[index]; - // Long labels are preferred - if (typeof labels_long[index] !== "undefined") - date = labels_long[index]; - else if (typeof labels[index] !== "undefined") date = labels[index]; + result.push({ + date: date, + value: value, + label: dataObject.label + }); + }); + } - result.push({ - date: date, - value: value, - label: dataObject.label, - }); - }); - } + if (typeof result === "undefined") throw new Error("Empty result"); - if (typeof result === "undefined") throw new Error("Empty result"); + return result; + }; - return result; - }; + try { + var elements = []; + var custom_graph = $("input:hidden[name=custom_graph]").value; - try { - var elements = []; - var custom_graph = $("input:hidden[name=custom_graph]").value; + if (custom_graph) { + dataObject = retrieveDataOject(dataObjects); + dataObjects.forEach(function(element) { + elements.push(processDataObject(element)); + }); + graphData = elements; + } else { + dataObject = retrieveDataOject(dataObjects); + elements.push(processDataObject(dataObject)); + graphData = elements; + } - if (custom_graph) { - dataObject = retrieveDataOject(dataObjects); - dataObjects.forEach(function (element) { - elements.push(processDataObject(element)); - }); - graphData = elements; - } else { - dataObject = retrieveDataOject(dataObjects); - elements.push(processDataObject(dataObject)); - graphData = elements; - } + // Transform the object data into a string + // cause PHP has limitations in the number + // of POST params received. + var graphDataStr = JSON.stringify(graphData); - // Transform the object data into a string - // cause PHP has limitations in the number - // of POST params received. - var graphDataStr = JSON.stringify(graphData); + // Build form + var $form = $("
"), + $dataInput = $(""), + $typeInput = $(""), + $separatorInput = $(""), + $excelInput = $(""); - // Build form - var $form = $("
"), - $dataInput = $(""), - $typeInput = $(""), - $separatorInput = $(""), - $excelInput = $(""); + $dataInput + .prop("name", "data") + .prop("type", "text") + .prop("value", graphDataStr); - $dataInput - .prop("name", "data") - .prop("type", "text") - .prop("value", graphDataStr); + $typeInput + .prop("name", "type") + .prop("type", "text") + .prop("value", type); - $typeInput - .prop("name", "type") - .prop("type", "text") - .prop("value", type); + $separatorInput + .prop("name", "separator") + .prop("type", "text") + .prop("value", ";"); - $separatorInput - .prop("name", "separator") - .prop("type", "text") - .prop("value", ";"); + $excelInput + .prop("name", "excel_encoding") + .prop("type", "text") + .prop("value", 0); - $excelInput - .prop("name", "excel_encoding") - .prop("type", "text") - .prop("value", 0); + $form + .prop("method", "POST") + .prop( + "action", + plot.getOptions().export.homeurl + "include/graphs/export_data.php" + ) + .append($dataInput, $typeInput, $separatorInput, $excelInput) + .hide() + // Firefox made me write into the DOM for this :( + .appendTo("body") + .submit(); + } catch (e) { + alert("There was an error exporting the data"); + } + }; + } - $form - .prop("method", "POST") - .prop( - "action", - plot.getOptions().export.homeurl + "include/graphs/export_data.php" - ) - .append($dataInput, $typeInput, $separatorInput, $excelInput) - .hide() - // Firefox made me write into the DOM for this :( - .appendTo("body") - .submit(); - } catch (e) { - alert("There was an error exporting the data"); - } - }; - } - - $.plot.plugins.push({ - init: init, - options: options, - name: "exportdata", - version: "0.1", - }); + $.plot.plugins.push({ + init: init, + options: options, + name: "exportdata", + version: "0.1" + }); })(jQuery); diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index dc4e556292..81c9cc79cf 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -346,13 +346,7 @@ function menu_graph( $threshold = true; } - $return .= "