2012-06-07 13:44:08 +02:00
|
|
|
<?php
|
|
|
|
|
2021-11-04 16:28:15 +01:00
|
|
|
// Pandora FMS - http://pandorafms.com
|
2012-06-07 13:44:08 +02:00
|
|
|
// ==================================================
|
2020-11-27 13:52:35 +01:00
|
|
|
// Copyright (c) 2011-2021 Artica Soluciones Tecnologicas
|
2012-06-07 13:44:08 +02:00
|
|
|
// Please see http://pandorafms.org for full contribution list
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation; version 2
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
// Get critical agents by using the status code in modules.
|
2019-01-30 16:18:44 +01:00
|
|
|
function os_agents_critical($id_os)
|
|
|
|
{
|
2022-05-10 10:01:17 +02:00
|
|
|
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)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2012-06-07 13:44:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
// Get ok agents by using the status code in modules.
|
|
|
|
function os_agents_ok($id_os)
|
|
|
|
{
|
2022-05-10 10:01:17 +02:00
|
|
|
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)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2012-06-07 13:44:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
// Get warning agents by using the status code in modules.
|
|
|
|
function os_agents_warning($id_os)
|
|
|
|
{
|
2022-05-10 10:01:17 +02:00
|
|
|
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)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2012-06-07 13:44:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
// Get unknown agents by using the status code in modules.
|
|
|
|
function os_agents_unknown($id_os)
|
|
|
|
{
|
2022-05-10 10:01:17 +02:00
|
|
|
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)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2012-06-07 13:44:08 +02:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2012-11-26 17:44:41 +01:00
|
|
|
// Get the name of a group given its id.
|
2019-01-30 16:18:44 +01:00
|
|
|
function os_get_name($id_os)
|
|
|
|
{
|
|
|
|
return db_get_value('name', 'tconfig_os', 'id_os', (int) $id_os);
|
2012-11-26 17:44:41 +01:00
|
|
|
}
|
|
|
|
|
2014-12-19 18:39:18 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
function os_get_os($hash=false)
|
|
|
|
{
|
|
|
|
$result = [];
|
|
|
|
$op_systems = db_get_all_rows_in_table('tconfig_os');
|
|
|
|
if (empty($op_systems)) {
|
|
|
|
$op_systems = [];
|
|
|
|
}
|
2019-01-11 08:45:12 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
if ($hash) {
|
|
|
|
foreach ($op_systems as $key => $value) {
|
|
|
|
$result[$value['id_os']] = $value['name'];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$result = $op_systems;
|
|
|
|
}
|
2019-01-11 08:45:12 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
return $result;
|
2014-12-19 18:39:18 +01:00
|
|
|
}
|
2018-01-29 16:48:21 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
function os_get_icon($id_os)
|
|
|
|
{
|
|
|
|
return db_get_value('icon_name', 'tconfig_os', 'id_os', (int) $id_os);
|
2018-01-29 16:48:21 +01:00
|
|
|
}
|