diff --git a/pandora_console/include/class/HTML.class.php b/pandora_console/include/class/HTML.class.php index 002c91f181..376afc4bfd 100644 --- a/pandora_console/include/class/HTML.class.php +++ b/pandora_console/include/class/HTML.class.php @@ -764,8 +764,10 @@ class HTML $output_head .= $data['pre-content']; } - $output_head .= '
'; + if (isset($data['form']) === true) { + $output_head .= ''; + } if ($return === false) { echo $output_head; diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index 1d43091d2a..8bf095a07f 100644 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -262,6 +262,8 @@ define('SERVICE_STATUS_ALERT', 4); // Default weights. define('SERVICE_WEIGHT_CRITICAL', 1); define('SERVICE_WEIGHT_WARNING', 0.5); +define('SERVICE_SMART_WEIGHT_CRITICAL', 50); +define('SERVICE_SMART_WEIGHT_WARNING', 30); define('SERVICE_ELEMENT_WEIGHT_CRITICAL', 1); define('SERVICE_ELEMENT_WEIGHT_WARNING', 0.5); define('SERVICE_ELEMENT_WEIGHT_OK', 0); diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index b266409d43..f25b712b54 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -1647,7 +1647,6 @@ function html_print_input_range( } $output .= ' id="'.$id.'" '; - $output .= ' return="'.$return.'" '; $output .= ' min="'.$min.'" '; $output .= ' max="'.$max.'" '; $output .= ' step="'.$step.'" '; @@ -4092,7 +4091,7 @@ function html_print_input($data, $wrapper='div', $input_only=false) case 'interval': $output .= html_print_extended_select_for_time( $data['name'], - $data['value'], + ((isset($data['value']) === true) ? $data['value'] : $data['selected']), ((isset($data['script']) === true) ? $data['script'] : ''), ((isset($data['nothing']) === true) ? $data['nothing'] : ''), ((isset($data['nothing_value']) === true) ? $data['nothing_value'] : 0), diff --git a/pandora_console/include/lib/Module.php b/pandora_console/include/lib/Module.php index 60b75580ce..570425bd68 100644 --- a/pandora_console/include/lib/Module.php +++ b/pandora_console/include/lib/Module.php @@ -167,6 +167,104 @@ class Module extends Entity } + /** + * Retrieve all alert templates (ids) assigned to current module. + * + * @return array Of ids. + */ + public function alertTemplatesAssigned() + { + if ($this->id_agente_modulo() === null) { + // Need to be stored first. + return []; + } + + $result = db_get_all_rows_filter( + 'talert_template_modules', + ['id_agent_module' => $this->id_agente_modulo()], + 'id_alert_template' + ); + + if ($result === false) { + return []; + } + + return array_reduce( + $result, + function ($carry, $item) { + $carry[] = $item['id_alert_template']; + return $carry; + }, + [] + ); + } + + + /** + * Remove a alert template assignment. + * + * @param integer $id_alert_template Target id. + * + * @return boolean Success or not. + */ + public function unassignAlertTemplate(int $id_alert_template) + { + if ($this->id_agente_modulo() === null) { + // Need to be stored first. + return false; + } + + if (is_numeric($id_alert_template) === false + || $id_alert_template <= 0 + ) { + // Invalid alert template. + return false; + } + + return (bool) \db_process_sql_delete( + 'talert_template_modules', + [ + 'id_agent_module' => $this->id_agente_modulo(), + 'id_alert_template' => $id_alert_template, + ] + ); + + } + + + /** + * Add an alert template to this module. + * + * @param integer|null $id_alert_template Target alert template. + * + * @return boolean Status of adding process. + */ + public function addAlertTemplate(?int $id_alert_template=null) + { + if ($this->id_agente_modulo() === null) { + // Need to be stored first. + return false; + } + + if (is_numeric($id_alert_template) === false + || $id_alert_template <= 0 + ) { + // Invalid alert template. + return false; + } + + return (bool) \db_process_sql_insert( + 'talert_template_modules', + [ + 'id_agent_module' => $this->id_agente_modulo(), + 'id_alert_template' => $id_alert_template, + 'last_reference' => time(), + ] + ); + + } + + /** * Saves current definition to database. * @@ -250,4 +348,49 @@ class Module extends Entity } + /** + * Transforms results from classic mode into modern exceptions. + * + * @param integer|boolean $result Result received from module management. + * + * @return integer Module id created or result. + * @throws \Exception On error. + */ + public static function errorToException($result) + { + if ($result === ERR_INCOMPLETE) { + throw new \Exception( + __('Module name empty.') + ); + } + + if ($result === ERR_GENERIC) { + throw new \Exception( + __('Invalid characters in module name') + ); + } + + if ($result === ERR_EXIST) { + throw new \Exception( + __('Module already exists please select another name or agent.') + ); + } + + if ($result === false) { + throw new \Exception( + __('Insufficent permissions to perform this action') + ); + } + + if ($result === ERR_DB) { + global $config; + throw new \Exception( + __('Error while processing: %s', $config['dbconnection']->error) + ); + } + + return $result; + } + + }