Services review

This commit is contained in:
fbsanchez 2020-06-24 18:01:34 +02:00
parent 94a7b625fb
commit 45a161426b
4 changed files with 150 additions and 4 deletions

View File

@ -764,8 +764,10 @@ class HTML
$output_head .= $data['pre-content'];
}
$output_head .= '<form id="'.$form['id'].'" class="discovery '.$form['class'].'" onsubmit="'.$form['onsubmit'].'" enctype="'.$form['enctype'].'" action="'.$form['action'].'" method="'.$form['method'];
$output_head .= '" '.$form['extra'].'>';
if (isset($data['form']) === true) {
$output_head .= '<form name="'.$form['name'].'" id="'.$form['id'].'" class="discovery '.$form['class'].'" onsubmit="'.$form['onsubmit'].'" enctype="'.$form['enctype'].'" action="'.$form['action'].'" method="'.$form['method'];
$output_head .= '" '.$form['extra'].'>';
}
if ($return === false) {
echo $output_head;

View File

@ -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);

View File

@ -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),

View File

@ -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;
}
}