mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
thing from sysa
git-svn-id: http://www.observium.org/svn/observer/trunk@2321 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
121
irc.php
121
irc.php
@@ -1,10 +1,6 @@
|
||||
#!/usr/bin/env php
|
||||
|
||||
# status <dev prt srv>
|
||||
# reboot
|
||||
# log
|
||||
# help
|
||||
# down
|
||||
# port_info is broken. always reports same values no matter host selected
|
||||
|
||||
<?php
|
||||
|
||||
@@ -23,13 +19,32 @@ mysql_close();
|
||||
# Redirect to /dev/null if you aren't using screen to keep tabs
|
||||
echo "Observer Bot Starting ...\n";
|
||||
echo "\n";
|
||||
echo "COMMAND\t\tHOST\t\t\tDEVICE\n";
|
||||
echo "-------\t\t----\t\t\t------\n";
|
||||
echo "Timestamp Command\n";
|
||||
echo "----------------- ------- \n";
|
||||
|
||||
class observiumbot
|
||||
|
||||
{
|
||||
|
||||
|
||||
###
|
||||
# Get HELP!
|
||||
###
|
||||
function help_info(&$irc, &$data)
|
||||
{
|
||||
|
||||
global $config;
|
||||
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Commands: !help, !log, !status, !version, !down, !port, !device, !listdevices");
|
||||
|
||||
echo date("m-d-y H:i:s ");
|
||||
echo "HELP\n";
|
||||
|
||||
mysql_close();
|
||||
|
||||
}
|
||||
|
||||
|
||||
###
|
||||
# Get status on !version
|
||||
###
|
||||
@@ -40,12 +55,38 @@ global $config;
|
||||
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Observium Version " . $config['version']);
|
||||
|
||||
echo date("m-d-y H:i:s ");
|
||||
echo "VERSION\t\t". $config['version'] . "\n";
|
||||
|
||||
mysql_close();
|
||||
|
||||
}
|
||||
|
||||
###
|
||||
# Get last eventlog entry
|
||||
###
|
||||
function log_info(&$irc, &$data)
|
||||
{
|
||||
|
||||
global $config;
|
||||
|
||||
mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);
|
||||
mysql_select_db($config['db_name']);
|
||||
|
||||
$device = dbFetchRow("SELECT `event_id`,`host`,`datetime`,`message`,`type` FROM `eventlog` ORDER BY `event_id` DESC LIMIT 1");
|
||||
$host=$device['host'];
|
||||
$hostid = dbFetchRow("SELECT `hostname` FROM `devices` WHERE `device_id` = $host");
|
||||
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $device['event_id'] ." ". $hostid['hostname'] ." ". $device['datetime'] ." ". $device['message'] ." ". $device['type']);
|
||||
|
||||
echo date("m-d-y H:i:s ");
|
||||
echo "LOG\n";
|
||||
|
||||
mysql_close();
|
||||
|
||||
}
|
||||
|
||||
|
||||
###
|
||||
# Get status on !down devices
|
||||
###
|
||||
@@ -56,18 +97,16 @@ global $config;
|
||||
mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);
|
||||
mysql_select_db($config['db_name']);
|
||||
|
||||
$query = mysql_query("SELECT * FROM `devices` where status=0");
|
||||
unset($message);
|
||||
while($device = mysql_fetch_assoc($query))
|
||||
foreach (dbFetchRows("SELECT * FROM `devices` where status=0") as $device)
|
||||
{
|
||||
$message .= $sep . $device['hostname'];
|
||||
$sep = ", ";
|
||||
}
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $message);
|
||||
unset($sep);
|
||||
|
||||
mysql_close();
|
||||
|
||||
echo date("m-d-y H:i:s ");
|
||||
echo "DOWN\n";
|
||||
|
||||
}
|
||||
@@ -92,9 +131,10 @@ mysql_close();
|
||||
if ($device['ignore']) { $status = "*Ignored*"; }
|
||||
if ($device['disabled']) { $status = "*Disabled*"; }
|
||||
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, '#'.$device['device_id'] . " " . $device['os'] . " " . $device['version'] . " " .
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $device['os'] . " " . $device['version'] . " " .
|
||||
$device['features'] . " " . $status);
|
||||
|
||||
echo date("m-d-y H:i:s ");
|
||||
echo "DEVICE\t\t". $device['hostname']."\n";
|
||||
|
||||
}
|
||||
@@ -122,10 +162,11 @@ mysql_close();
|
||||
$pps_in = format_bi($port['ifInUcastPkts_rate']);
|
||||
$pps_out = format_bi($port['ifOutUcastPkts_rate']);
|
||||
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, '#' . $port['interface_id'] . " " . $port['ifAdminStatus'] . "/" . $port['ifOperStatus'] . " " .
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $port['ifAdminStatus'] . "/" . $port['ifOperStatus'] . " " .
|
||||
$bps_in. " > bps > " . $bps_out . " | " . $pps_in. "pps > PPS > " . $pps_out ."pps");
|
||||
|
||||
echo "PORT\t\t" . $hostname . "\t". $ifname . "\n";
|
||||
echo date("m-d-y H:i:s ");
|
||||
echo "PORT\t\t\t" . $hostname . "\t". $ifname . "\n";
|
||||
|
||||
}
|
||||
|
||||
@@ -152,9 +193,58 @@ mysql_close();
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $message);
|
||||
unset($sep);
|
||||
|
||||
echo date("m-d-y H:i:s ");
|
||||
echo "LISTDEVICES\n";
|
||||
|
||||
}
|
||||
|
||||
|
||||
###
|
||||
# !status <dev prt srv> gives overall status
|
||||
###
|
||||
function status_info(&$irc, &$data)
|
||||
{
|
||||
$statustype = $data->messageex[1];
|
||||
|
||||
global $config;
|
||||
mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);
|
||||
mysql_select_db($config['db_name']);
|
||||
|
||||
if ($statustype == "dev") {
|
||||
$devcount = array_pop(dbFetchRow("SELECT count(*) FROM devices"));
|
||||
$devup = array_pop(dbFetchRow("SELECT count(*) FROM devices WHERE status = '1' AND `ignore` = '0'"));
|
||||
$devdown = array_pop(dbFetchRow("SELECT count(*) FROM devices WHERE status = '0' AND `ignore` = '0'"));
|
||||
$devign = array_pop(dbFetchRow("SELECT count(*) FROM devices WHERE `ignore` = '1'"));
|
||||
$devdis = array_pop(dbFetchRow("SELECT count(*) FROM devices WHERE `disabled` = '1'"));
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Devices: " .$devcount . " (" .$devup . " up, " .$devdown . " down, " .$devign . " ignored, " .$devdis . " disabled" . ")"); }
|
||||
|
||||
else if ($statustype == "prt") {
|
||||
$prtcount = array_pop(dbFetchRow("SELECT count(*) FROM ports"));
|
||||
$prtup = array_pop(dbFetchRow("SELECT count(*) FROM ports AS I, devices AS D WHERE I.ifOperStatus = 'up' AND I.ignore = '0' AND I.device_id = D.device_id AND D.ignore = '0'"));
|
||||
$prtdown = array_pop(dbFetchRow("SELECT count(*) FROM ports AS I, devices AS D WHERE I.ifOperStatus = 'down' AND I.ifAdminStatus = 'up' AND I.ignore = '0' AND D.device_id = I.device_id AND D.ignore = '0'"));
|
||||
$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'"));
|
||||
$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')"));
|
||||
$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')"));
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Ports: " .$prtcount . " (" .$prtup . " up, " .$prtdown . " down, " .$prtign . " ignored, " .$prtsht . " shutdown" . ")");}
|
||||
|
||||
else if ($statustype == "srv") {
|
||||
$srvcount = array_pop(dbFetchRow("SELECT count(service_id) FROM services"));
|
||||
$srvup = array_pop(dbFetchRow("SELECT count(service_id) FROM services WHERE service_status = '1' AND service_ignore ='0'"));
|
||||
$srvdown = array_pop(dbFetchRow("SELECT count(service_id) FROM services WHERE service_status = '0' AND service_ignore = '0'"));
|
||||
$srvign = array_pop(dbFetchRow("SELECT count(service_id) FROM services WHERE service_ignore = '1'"));
|
||||
$srvdis = array_pop(dbFetchRow("SELECT count(service_id) FROM services WHERE service_disabled = '1'"));
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Services: " .$srvcount . " (" .$srvup . " up, " .$srvdown . " down, " .$srvign . " ignored, " .$srvdis . " disabled" . ")"); }
|
||||
|
||||
else {
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Error: STATUS requires one of the following <dev prt srv>"); }
|
||||
|
||||
mysql_close();
|
||||
|
||||
echo date("m-d-y H:i:s ");
|
||||
echo "STATUS\t\t$statustype\n";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$bot = &new observiumbot();
|
||||
@@ -166,6 +256,9 @@ $irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!device', $bot, 'device_info
|
||||
$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!port', $bot, 'port_info');
|
||||
$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!down', $bot, 'down_info');
|
||||
$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!version', $bot, 'version_info');
|
||||
$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!status', $bot, 'status_info');
|
||||
$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!log', $bot, 'log_info');
|
||||
$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!help', $bot, 'help_info');
|
||||
|
||||
$irc->connect($config['irc_host'], $config['irc_port']);
|
||||
$irc->login($config['irc_nick'], 'Observium Bot', 0, $config['irc_nick']);
|
||||
|
Reference in New Issue
Block a user