mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
alerts: Adde generic alerts for state sensors (#7812)
* feature: Generic alerts for state sensors A bit of a hack, but gets the job done. Perhaps someone can refactor the ResolveGlues() function sometime to make it better. * Fix mistakes * Add docs and collection rules, critical enabled by default * moved schema file to 221.sql
This commit is contained in:
committed by
Neil Lathwood
parent
5357dd9515
commit
5405498ed6
@@ -125,6 +125,14 @@ Description: Only selects sensors that have a port linked to them, the port is u
|
|||||||
|
|
||||||
Source: `(%sensors.entity_link_type = 'port' && %sensors.entity_link_index = %ports.ifIndex && %macros.port_up && %macros.device_up))`
|
Source: `(%sensors.entity_link_type = 'port' && %sensors.entity_link_index = %ports.ifIndex && %macros.port_up && %macros.device_up))`
|
||||||
|
|
||||||
|
## State Sensors (Boolean)
|
||||||
|
|
||||||
|
Entity: `%macros.state_sensor_ok`, `%macros.state_sensor_warning`, `%macros.state_sensor_critical`, `%macros.state_sensor_unknown`
|
||||||
|
|
||||||
|
Description: Select state sensors by their generic status ok (0), warning (1), critical (2), unknown (3)
|
||||||
|
|
||||||
|
Source: `(%sensors.sensor_current = %state_translations.state_value && %state_translations.state_generic_value = 2)`
|
||||||
|
|
||||||
## Misc (Boolean)
|
## Misc (Boolean)
|
||||||
|
|
||||||
### Packet Loss
|
### Packet Loss
|
||||||
|
@@ -1353,7 +1353,7 @@ function get_port_id($ports_mapped, $port, $port_association_mode)
|
|||||||
* @param int $x Recursion Anchor
|
* @param int $x Recursion Anchor
|
||||||
* @param array $hist History of processed tables
|
* @param array $hist History of processed tables
|
||||||
* @param array $last Glues on the fringe
|
* @param array $last Glues on the fringe
|
||||||
* @return string|boolean
|
* @return array|false
|
||||||
*/
|
*/
|
||||||
function ResolveGlues($tables, $target, $x = 0, $hist = array(), $last = array())
|
function ResolveGlues($tables, $target, $x = 0, $hist = array(), $last = array())
|
||||||
{
|
{
|
||||||
@@ -1370,6 +1370,16 @@ function ResolveGlues($tables, $target, $x = 0, $hist = array(), $last = array()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
foreach ($tables as $table) {
|
foreach ($tables as $table) {
|
||||||
|
if ($table == 'state_translations' && ($target == 'device_id' || $target == 'sensor_id')) {
|
||||||
|
// workaround for state_translations
|
||||||
|
$st_tables = array(
|
||||||
|
'state_translations.state_index_id',
|
||||||
|
'sensors_to_state_indexes.sensor_id',
|
||||||
|
"sensors.$target",
|
||||||
|
);
|
||||||
|
return array_merge($last, $st_tables);
|
||||||
|
}
|
||||||
|
|
||||||
$glues = dbFetchRows('SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_NAME = ? && COLUMN_NAME LIKE "%\_id"', array($table));
|
$glues = dbFetchRows('SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_NAME = ? && COLUMN_NAME LIKE "%\_id"', array($table));
|
||||||
if (sizeof($glues) == 1 && $glues[0]['COLUMN_NAME'] != $target) {
|
if (sizeof($glues) == 1 && $glues[0]['COLUMN_NAME'] != $target) {
|
||||||
//Search for new candidates to expand
|
//Search for new candidates to expand
|
||||||
|
@@ -58,6 +58,16 @@
|
|||||||
"name": "Wireless Sensor under limit",
|
"name": "Wireless Sensor under limit",
|
||||||
"default": true
|
"default": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"rule": "%macros.state_sensor_critical",
|
||||||
|
"name": "State Sensor Critical",
|
||||||
|
"default": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"rule": "%macros.state_sensor_warning",
|
||||||
|
"name": "State Sensor Warning",
|
||||||
|
"default": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"rule": "%macros.bill_quota_over_quota >= \"75\"",
|
"rule": "%macros.bill_quota_over_quota >= \"75\"",
|
||||||
"name": "Quota bills over 75% used"
|
"name": "Quota bills over 75% used"
|
||||||
@@ -306,5 +316,5 @@
|
|||||||
"rule": "%sensors.sensor_current = \"3\" && %sensors.sensor_oid = \".1.3.6.1.4.1.4413.1.1.43.1.15.1.2.1\"",
|
"rule": "%sensors.sensor_current = \"3\" && %sensors.sensor_oid = \".1.3.6.1.4.1.4413.1.1.43.1.15.1.2.1\"",
|
||||||
"name": "UBNT EdgeSwitch Chassis state failed"
|
"name": "UBNT EdgeSwitch Chassis state failed"
|
||||||
}
|
}
|
||||||
|
|
||||||
]
|
]
|
||||||
|
4
sql-schema/221.sql
Normal file
4
sql-schema/221.sql
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
INSERT INTO `config` (`config_name`,`config_value`,`config_default`,`config_descr`,`config_group`,`config_group_order`,`config_sub_group`,`config_sub_group_order`,`config_hidden`,`config_disabled`) VALUES ('alert.macros.rule.state_sensor_ok','%sensors.sensor_current = %state_translations.state_value && %state_translations.state_generic_value = 0','%sensors.sensor_current = %state_translations.state_value && %state_translations.state_generic_value = 0','Ok state sensors','alerting',0,'macros',0,'1','0');
|
||||||
|
INSERT INTO `config` (`config_name`,`config_value`,`config_default`,`config_descr`,`config_group`,`config_group_order`,`config_sub_group`,`config_sub_group_order`,`config_hidden`,`config_disabled`) VALUES ('alert.macros.rule.state_sensor_warning','%sensors.sensor_current = %state_translations.state_value && %state_translations.state_generic_value = 1','%sensors.sensor_current = %state_translations.state_value && %state_translations.state_generic_value = 1','Warning state sensors','alerting',0,'macros',0,'1','0');
|
||||||
|
INSERT INTO `config` (`config_name`,`config_value`,`config_default`,`config_descr`,`config_group`,`config_group_order`,`config_sub_group`,`config_sub_group_order`,`config_hidden`,`config_disabled`) VALUES ('alert.macros.rule.state_sensor_critical','%sensors.sensor_current = %state_translations.state_value && %state_translations.state_generic_value = 2','%sensors.sensor_current = %state_translations.state_value && %state_translations.state_generic_value = 2','Critical state sensors','alerting',0,'macros',0,'1','0');
|
||||||
|
INSERT INTO `config` (`config_name`,`config_value`,`config_default`,`config_descr`,`config_group`,`config_group_order`,`config_sub_group`,`config_sub_group_order`,`config_hidden`,`config_disabled`) VALUES ('alert.macros.rule.state_sensor_unknown','%sensors.sensor_current = %state_translations.state_value && %state_translations.state_generic_value = 3','%sensors.sensor_current = %state_translations.state_value && %state_translations.state_generic_value = 3','Unknown state sensors','alerting',0,'macros',0,'1','0');
|
@@ -147,4 +147,33 @@ class CommonFunctionsTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertFalse(is_valid_hostname('-'), '-');
|
$this->assertFalse(is_valid_hostname('-'), '-');
|
||||||
$this->assertFalse(is_valid_hostname(''), 'Empty string');
|
$this->assertFalse(is_valid_hostname(''), 'Empty string');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testResolveGlues()
|
||||||
|
{
|
||||||
|
if (getenv('DBTEST')) {
|
||||||
|
dbConnect();
|
||||||
|
dbBeginTransaction();
|
||||||
|
} else {
|
||||||
|
$this->markTestSkipped('Database tests not enabled. Set DBTEST=1 to enable.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertFalse(ResolveGlues(array('dbSchema'), 'device_id'));
|
||||||
|
|
||||||
|
$this->assertSame(array('devices.device_id'), ResolveGlues(array('devices'), 'device_id'));
|
||||||
|
$this->assertSame(array('sensors.device_id'), ResolveGlues(array('sensors'), 'device_id'));
|
||||||
|
|
||||||
|
// does not work right with current code
|
||||||
|
// $expected = array('bill_data.bill_id', 'bill_ports.port_id', 'ports.device_id');
|
||||||
|
// $this->assertSame($expected, ResolveGlues(array('bill_data'), 'device_id'));
|
||||||
|
|
||||||
|
$expected = array('state_translations.state_index_id', 'sensors_to_state_indexes.sensor_id', 'sensors.device_id');
|
||||||
|
$this->assertSame($expected, ResolveGlues(array('state_translations'), 'device_id'));
|
||||||
|
|
||||||
|
$expected = array('ipv4_addresses.port_id', 'ports.device_id');
|
||||||
|
$this->assertSame($expected, ResolveGlues(array('ipv4_addresses'), 'device_id'));
|
||||||
|
|
||||||
|
if (getenv('DBTEST')) {
|
||||||
|
dbRollbackTransaction();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user