mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
IRC bot updates. We should make this mofo AWESOMES.
git-svn-id: http://www.observium.org/svn/observer/trunk@2133 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@ -179,6 +179,13 @@ $config['ignore_mount_optical'] = 1; # Ignore mounted optical discs
|
||||
$config['device_traffic_iftype'] = array('/loopback/','/tunnel/','/virtual/','/mpls/','/ieee8023adLag/');
|
||||
$config['device_traffic_descr'] = array('/loopback/','/vlan/','/tunnel/','/:\d+/','/bond/');
|
||||
|
||||
### IRC Bot configuration
|
||||
|
||||
$config['irc_host'] = "chat.eu.freenode.net";
|
||||
$config['irc_port'] = 6667;
|
||||
$config['irc_nick'] = "Observium";
|
||||
$config['irc_chan'][] = "#observium";
|
||||
|
||||
### Authentication
|
||||
|
||||
$config['allow_unauth_graphs'] = 0; ## Allow graphs to be viewed by anyone
|
||||
|
33
irc.php
33
irc.php
@ -20,7 +20,7 @@ class observiumbot
|
||||
if ($device['ignore']) { $status = "*Ignored*"; }
|
||||
if ($device['disabled']) { $status = "*Disabled*"; }
|
||||
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, 'id'.$device['device_id'] . " " . $device['os'] . " " . $device['version'] . " " .
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, '#'.$device['device_id'] . " " . $device['os'] . " " . $device['version'] . " " .
|
||||
$device['features'] . " " . $status);
|
||||
}
|
||||
|
||||
@ -30,34 +30,43 @@ class observiumbot
|
||||
$ifname = $data->messageex[2];
|
||||
|
||||
$device = mysql_fetch_assoc(mysql_query("SELECT * FROM `devices` WHERE `hostname` = '".mres($hostname)."'"));
|
||||
$port = mysql_fetch_assoc(mysql_query("SELECT * FROM `ports` WHERE `ifName` = '".$ifname."' OR `ifDescr` = '".$ifname."' AND device_id = '".$device['device_id']."'"));
|
||||
$port = mysql_fetch_assoc(mysql_query("SELECT * FROM `ports` WHERE `ifName` = '".mres($ifname)."' OR `ifDescr` = '".mres($ifname)."' AND device_id = '".$device['device_id']."'"));
|
||||
|
||||
$bps_in = formatRates($port['ifInOctets_rate']);
|
||||
$bps_out = formatRates($port['ifOutOctets_rate']);
|
||||
$pps_in = format_bi($port['ifInUcastPkts_rate']);
|
||||
$pps_out = format_bi($port['ifOutUcastPkts_rate']);
|
||||
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, 'id' . $port['interface_id'] . " " . $port['ifAdminStatus'] . "/" . $port['ifOperStatus'] . " " .
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, '#' . $port['interface_id'] . " " . $port['ifAdminStatus'] . "/" . $port['ifOperStatus'] . " " .
|
||||
$bps_in. " > bps > " . $bps_out . " | " . $pps_in. "pps > PPS > " . $pps_out ."pps");
|
||||
}
|
||||
}
|
||||
|
||||
$host = "chat.eu.freenode.net";
|
||||
$port = 6667;
|
||||
$nick = "Observium";
|
||||
$chan = "#observium";
|
||||
function list_devices(&$irc, &$data)
|
||||
{
|
||||
$query = mysql_query("SELECT * FROM `devices`");
|
||||
unset($message);
|
||||
while($device = mysql_fetch_assoc($query))
|
||||
{
|
||||
$message .= $sep . $device['hostname'];
|
||||
$sep = ", ";
|
||||
}
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $message);
|
||||
unset($sep);
|
||||
}
|
||||
}
|
||||
|
||||
$bot = &new observiumbot();
|
||||
$irc = &new Net_SmartIRC();
|
||||
$irc->setUseSockets(TRUE);
|
||||
|
||||
$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!listdevices', $bot, 'list_devices');
|
||||
$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!device', $bot, 'device_info');
|
||||
$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!port', $bot, 'port_info');
|
||||
|
||||
$irc->connect($host, $port);
|
||||
$irc->login($nick, 'Observium Bot', 0, $nick);
|
||||
$irc->join(array($chan));
|
||||
$irc->connect($config['irc_host'], $config['irc_port']);
|
||||
$irc->login($config['irc_nick'], 'Observium Bot', 0, $config['irc_nick']);
|
||||
$irc->join($config['irc_chan']);
|
||||
$irc->listen();
|
||||
$irc->disconnect();
|
||||
|
||||
?>
|
||||
?>
|
||||
|
Reference in New Issue
Block a user