Merge branch 'ent-8209-Problemas-Odometer-Consola-Visual' into 'develop'

Ent 8209 problemas odometer consola visual

See merge request artica/pandorafms!4512
This commit is contained in:
Daniel Rodriguez 2021-11-02 14:31:56 +00:00
commit 845275b947
2 changed files with 45 additions and 61 deletions

View File

@ -3848,13 +3848,28 @@ function modules_get_state_condition($state, $prefix='tae')
function modules_get_min_max_data($id_agent_module, $time_init=0)
{
$table = modules_get_table_data($id_agent_module);
$data = db_get_all_rows_sql(
'SELECT min(datos) as min, max(datos) as max
FROM '.$table.'
WHERE id_agente_modulo = '.$id_agent_module.'
AND utimestamp >= '.$time_init
// Find the minimum and maximun value defined.
$sql = sprintf(
'SELECT `min`, `max` FROM %s
WHERE id_agente_modulo = %d',
'tagente_modulo',
$id_agent_module
);
$min_max = \db_get_row_sql($sql);
if ($min_max['min'] !== '0' || $min_max['max'] !== '0') {
$data[0]['min'] = $min_max['min'];
$data[0]['max'] = $min_max['max'];
} else {
// Search limits of the last two days.
$table = modules_get_table_data($id_agent_module);
$data = db_get_all_rows_sql(
'SELECT min(datos) as min, max(datos) as max
FROM '.$table.'
WHERE id_agente_modulo = '.$id_agent_module.'
AND utimestamp >= '.$time_init
);
}
return $data;
}

View File

@ -281,6 +281,14 @@ final class Odometer extends Item
}
}
$sql = sprintf(
'SELECT min_warning, max_warning, min_critical, max_critical FROM %s
WHERE id_agente_modulo = %d',
'tagente_modulo',
$moduleId
);
$thresholds = \db_get_row_sql($sql);
if (\modules_get_unit($moduleId) === '%') {
$data['odometerType'] = 'percent';
} else {
@ -296,17 +304,25 @@ final class Odometer extends Item
}
$data['min_max_value'] = json_encode($minMax);
if ($thresholds['min_warning'] != 0 && $thresholds['min_warning'] > $minMax['max']) {
$thresholds['min_warning'] = $minMax['max'];
}
if ($thresholds['max_warning'] != 0 && $thresholds['max_warning'] > $minMax['max']) {
$thresholds['max_warning'] = $minMax['max'];
}
if ($thresholds['min_critical'] != 0 && $thresholds['min_critical'] > $minMax['max']) {
$thresholds['min_critical'] = $minMax['max'];
}
if ($thresholds['max_critical'] != 0 && $thresholds['max_critical'] > $minMax['max']) {
$thresholds['max_critical'] = $minMax['max'];
}
}
}
$sql = sprintf(
'SELECT min_warning, max_warning, min_critical, max_critical FROM %s
WHERE id_agente_modulo = %d',
'tagente_modulo',
$moduleId
);
$thresholds = \db_get_row_sql($sql);
$data['thresholds'] = json_encode($thresholds);
$data['status'] = \modules_get_color_status(modules_get_agentmodule_last_status($moduleId));
@ -323,53 +339,6 @@ final class Odometer extends Item
}
/**
* Insert or update an item in the database
*
* @param array $data Unknown input data structure.
*
* @return integer The modeled element data structure stored into the DB.
*
* @overrides Model::save.
*/
public function save(array $data=[]): int
{
if (empty($data) === false) {
if (empty($data['id']) === true) {
// Insert.
$save = static::encode($data);
$result = \db_process_sql_insert('tlayout_data', $save);
if ($result !== false) {
$item = static::fromDB(['id' => $result]);
$item->setData($item->toArray());
}
} else {
// Update.
$dataModelEncode = $this->encode($this->toArray());
$dataEncode = $this->encode($data);
$save = array_merge($dataModelEncode, $dataEncode);
$result = \db_process_sql_update(
'tlayout_data',
$save,
['id' => $save['id']]
);
// Invalidate the item's cache.
if ($result !== false && $result > 0) {
$item = static::fromDB(['id' => $save['id']]);
// Update the model.
if (empty($item) === false) {
$this->setData($item->toArray());
}
}
}
}
return $result;
}
/**
* Generates inputs for form (specific).
*