mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
feature: Added some more coloring and make it easier to colorize messages for irc bot (#6759)
* Add some more coloring and make it easier to colorize messages * Refactor "_color"-function * Fix missing ) * Use _color() also in alerts * Fix some standard-errors
This commit is contained in:
@ -246,7 +246,7 @@ class IRCBot
|
||||
$severity_extended = '';
|
||||
endswitch;
|
||||
|
||||
$severity = str_replace(array('warning', 'critical'), array(chr(3).'8Warning', chr(3).'4Critical'), $alert['severity']).$severity_extended.chr(3).' ';
|
||||
$severity = str_replace(array('warning', 'critical'), array(_color('Warning', 'orange'), _color('Critical', 'red')), $alert['severity']).$severity_extended.' ';
|
||||
if ($alert['state'] == 0 and $this->config['irc_alert_utf8']) {
|
||||
$severity = str_replace(array('Warning', 'Critical'), array('̶W̶a̶r̶n̶i̶n̶g', '̶C̶r̶i̶t̶i̶c̶a̶l'), $severity);
|
||||
}
|
||||
@ -715,6 +715,15 @@ class IRCBot
|
||||
$devdown = array_pop(dbFetchRow("SELECT count(*) FROM devices WHERE status = '0' AND `ignore` = '0'".$d_a));
|
||||
$devign = array_pop(dbFetchRow("SELECT count(*) FROM devices WHERE `ignore` = '1'".$d_a));
|
||||
$devdis = array_pop(dbFetchRow("SELECT count(*) FROM devices WHERE `disabled` = '1'".$d_a));
|
||||
if ($devup > 0) {
|
||||
$devup = $this->_color($devup, 'green');
|
||||
}
|
||||
if ($devdown > 0) {
|
||||
$devdown = $this->_color($devdown, 'red');
|
||||
$devcount = $this->_color($devcount, 'orange', null, 'bold');
|
||||
} else {
|
||||
$devcount = $this->_color($devcount, 'green', null, 'bold');
|
||||
}
|
||||
$msg = 'Devices: '.$devcount.' ('.$devup.' up, '.$devdown.' down, '.$devign.' ignored, '.$devdis.' disabled'.')';
|
||||
break;
|
||||
|
||||
@ -727,6 +736,15 @@ class IRCBot
|
||||
$prtsht = array_pop(dbFetchRow("SELECT count(*) FROM ports AS I, devices AS D WHERE I.ifAdminStatus = 'down' AND I.ignore = '0' AND D.device_id = I.device_id AND D.ignore = '0'".$p_a));
|
||||
$prtign = array_pop(dbFetchRow("SELECT count(*) FROM ports AS I, devices AS D WHERE D.device_id = I.device_id AND (I.ignore = '1' OR D.ignore = '1')".$p_a));
|
||||
$prterr = array_pop(dbFetchRow("SELECT count(*) FROM ports AS I, devices AS D WHERE D.device_id = I.device_id AND (I.ignore = '0' OR D.ignore = '0') AND (I.ifInErrors_delta > '0' OR I.ifOutErrors_delta > '0')".$p_a));
|
||||
if ($prtup > 0) {
|
||||
$prtup = $this->_color($prtup, 'green');
|
||||
}
|
||||
if ($prtdown > 0) {
|
||||
$prtdown = $this->_color($prtdown, 'red');
|
||||
$prtcount = $this->_color($prtcount, 'orange', null, 'bold');
|
||||
} else {
|
||||
$prtcount = $this->_color($prtcount, 'green', null, 'bold');
|
||||
}
|
||||
$msg = 'Ports: '.$prtcount.' ('.$prtup.' up, '.$prtdown.' down, '.$prtign.' ignored, '.$prtsht.' shutdown'.')';
|
||||
break;
|
||||
|
||||
@ -738,6 +756,15 @@ class IRCBot
|
||||
$srvdown = array_pop(dbFetchRow("SELECT count(service_id) FROM services WHERE service_status = '0' AND service_ignore = '0'".$d_a));
|
||||
$srvign = array_pop(dbFetchRow("SELECT count(service_id) FROM services WHERE service_ignore = '1'".$d_a));
|
||||
$srvdis = array_pop(dbFetchRow("SELECT count(service_id) FROM services WHERE service_disabled = '1'".$d_a));
|
||||
if ($srvup > 0) {
|
||||
$srvup = $this->_color($srvup, 'green');
|
||||
}
|
||||
if ($srvdown > 0) {
|
||||
$srvdown = $this->_color($srvdown, 'red');
|
||||
$srvcount = $this->_color($srvcount, 'orange', null, 'bold');
|
||||
} else {
|
||||
$srvcount = $this->_color($srvcount, 'green', null, 'bold');
|
||||
}
|
||||
$msg = 'Services: '.$srvcount.' ('.$srvup.' up, '.$srvdown.' down, '.$srvign.' ignored, '.$srvdis.' disabled'.')';
|
||||
break;
|
||||
|
||||
@ -748,4 +775,48 @@ class IRCBot
|
||||
|
||||
return $this->respond($msg);
|
||||
}//end _status()
|
||||
|
||||
private function _color($text, $fg_color, $bg_color = null, $other = null)
|
||||
{
|
||||
$colors = array(
|
||||
'white' => "00",
|
||||
'black' => "01",
|
||||
'blue' => "02",
|
||||
'green' => "03",
|
||||
'red' => "04",
|
||||
'brown' => "05",
|
||||
'purple' => "06",
|
||||
'orange' => "07",
|
||||
'yellow' => "08",
|
||||
'lightgreen' => "09",
|
||||
'cyan' => "10",
|
||||
'lightcyan' => "11",
|
||||
'lightblue' => "12",
|
||||
'pink' => "13",
|
||||
'grey' => "14",
|
||||
'lightgrey' => "15",
|
||||
);
|
||||
$ret = chr(3);
|
||||
if (in_array($fg_color, $colors)) {
|
||||
$ret .= $colors[$fg_color];
|
||||
if (in_array($bg_color, $colors)) {
|
||||
$ret .= ",".$colors[$fg_color];
|
||||
}
|
||||
}
|
||||
switch ($other) {
|
||||
case 'bold':
|
||||
$ret .= chr(2);
|
||||
break;
|
||||
case 'underline':
|
||||
$ret .= chr(31);
|
||||
break;
|
||||
case 'italics':
|
||||
case 'reverse':
|
||||
$ret .= chr(22);
|
||||
break;
|
||||
}
|
||||
$ret .= $text;
|
||||
$ret .= chr(15);
|
||||
return $ret;
|
||||
}// end _color
|
||||
}//end class
|
||||
|
Reference in New Issue
Block a user