From b844dd44c8bd117a1e3bbac0a9592a8377dfb5ea Mon Sep 17 00:00:00 2001 From: TheGreatDoc <32565115+TheGreatDoc@users.noreply.github.com> Date: Sat, 21 Jul 2018 21:48:32 +0200 Subject: [PATCH] Asterisk Application support (#8914) DO NOT DELETE THIS TEXT #### Please note > Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting. - [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/) #### Testers If you would like to test this pull request then please run: `./scripts/github-apply `, i.e `./scripts/github-apply 5926` PR 183 from librenms-agent contains the script to make this work https://github.com/librenms/librenms-agent/pull/183 --- doc/Extensions/Applications.md | 22 +++++++++ html/includes/functions.inc.php | 3 ++ .../graphs/application/asterisk_calls.inc.php | 14 ++++++ .../application/asterisk_channels.inc.php | 14 ++++++ .../graphs/application/asterisk_sip.inc.php | 31 +++++++++++++ html/pages/apps.inc.php | 5 +++ html/pages/device/apps/asterisk.inc.php | 29 ++++++++++++ .../polling/applications/asterisk.inc.php | 45 +++++++++++++++++++ 8 files changed, 163 insertions(+) create mode 100644 html/includes/graphs/application/asterisk_calls.inc.php create mode 100644 html/includes/graphs/application/asterisk_channels.inc.php create mode 100644 html/includes/graphs/application/asterisk_sip.inc.php create mode 100644 html/pages/device/apps/asterisk.inc.php create mode 100644 includes/polling/applications/asterisk.inc.php diff --git a/doc/Extensions/Applications.md b/doc/Extensions/Applications.md index b32cd2af51..4ee2d65e30 100644 --- a/doc/Extensions/Applications.md +++ b/doc/Extensions/Applications.md @@ -36,6 +36,7 @@ After you have enabled the application module, it would be wise to then also ena The unix-agent does not have a discovery module, only a poller module. That poller module is always disabled by default. It needs to be manually enabled if using the agent. Some applications will be automatically enabled by the unix-agent poller module. It is better to ensure that your application is enabled for monitoring. You can check by following the steps under the `SNMP Extend` heading. 1. [Apache](#apache) - SNMP extend, Agent +1. [Asterisk](#asterisk) - SNMP extend 1. [BIND9/named](#bind9-aka-named) - SNMP extend, Agent 1. [C.H.I.P.](#chip) - SNMP extend 1. [DHCP Stats](#dhcp-stats) - SNMP extend @@ -115,6 +116,27 @@ snmpwalk localhost NET-SNMP-EXTEND-MIB (If you get error like "Can't locate LWP/Simple.pm". libwww-perl needs to be installed: apt-get install libwww-perl) 2. On the device page in Librenms, edit your host and check the `Apache` under the Applications tab. +### Asterisk +A small shell script that reports various Asterisk call status. + +##### SNMP Extend +1. Copy the [asterisk script](https://github.com/librenms/librenms-agent/blob/master/snmp/asterisk) to `/etc/snmp/` on your asterisk server. + +2. Run `chmod +x /etc/snmp/asterisk` + +3. Configure `ASCLI` in the script. + +4. Verify it is working by running `/etc/snmp/asterisk` + +5. Edit your snmpd.conf file (usually `/etc/snmp/snmpd.conf`) and add: +``` +extend asterisk /etc/snmp/asterisk +``` + +6. Restart snmpd on your host + +The application should be auto-discovered as described at the top of the page. If it is not, please follow the steps set out under `SNMP Extend` heading top of page. + ### BIND9 aka named 1: Create stats file with appropriate permissions: diff --git a/html/includes/functions.inc.php b/html/includes/functions.inc.php index 09b781805f..e9bd146086 100644 --- a/html/includes/functions.inc.php +++ b/html/includes/functions.inc.php @@ -141,6 +141,9 @@ function nicecase($item) case 'zfs': return 'ZFS'; + case 'asterisk': + return 'Asterisk'; + default: return ucfirst($item); } diff --git a/html/includes/graphs/application/asterisk_calls.inc.php b/html/includes/graphs/application/asterisk_calls.inc.php new file mode 100644 index 0000000000..6bd7ca7883 --- /dev/null +++ b/html/includes/graphs/application/asterisk_calls.inc.php @@ -0,0 +1,14 @@ + 'Total Sip Peers', + 'sipmononline' => 'Sip Mon Online', + 'sipmonoffline'=> 'Sip Mon Offline', + 'sipunmononline' => 'Sip Unmon Online', + 'sipunmonoffline' => 'Sip Unmon Offline' +); + +$colours = 'mixed'; +$rrd_list = array(); + +if (rrdtool_check_rrd_exists($rrd_filename)) { + foreach ($astsip_access_array as $ds => $descr) { + $rrd_list[$i]['filename'] = $rrd_filename; + $rrd_list[$i]['descr'] = $descr; + $rrd_list[$i]['ds'] = $ds; + $i++; + } +} else { + echo "file missing: $rrd_filename"; +} +require 'includes/graphs/generic_multi_line.inc.php'; diff --git a/html/pages/apps.inc.php b/html/pages/apps.inc.php index 3d1a5cdb48..7acbbe9f12 100644 --- a/html/pages/apps.inc.php +++ b/html/pages/apps.inc.php @@ -273,6 +273,11 @@ $graphs['powerdns-dnsdist'] = array( 'rules_stats', 'queries_drop', ); +$graphs['asterisk'] = array( + 'calls', + 'channels', + 'sip', +); echo '
'; echo '
'; echo "Apps » "; diff --git a/html/pages/device/apps/asterisk.inc.php b/html/pages/device/apps/asterisk.inc.php new file mode 100644 index 0000000000..76bab79b5c --- /dev/null +++ b/html/pages/device/apps/asterisk.inc.php @@ -0,0 +1,29 @@ + 'Asterisk - Calls', + 'asterisk_channels' => 'Asterisk - Channels', + 'asterisk_sip' => 'Asterisk - SIP' + ); + +foreach ($graphs as $key => $text) { + $graph_type = $key; + $graph_array['height'] = '100'; + $graph_array['width'] = '215'; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $app['app_id']; + $graph_array['type'] = 'application_'.$key; + + echo '
+
+

'.$text.'

+
+
+
'; + include 'includes/print-graphrow.inc.php'; + echo '
'; + echo '
'; + echo '
'; +} diff --git a/includes/polling/applications/asterisk.inc.php b/includes/polling/applications/asterisk.inc.php new file mode 100644 index 0000000000..0edbc3ecb0 --- /dev/null +++ b/includes/polling/applications/asterisk.inc.php @@ -0,0 +1,45 @@ +>>\n", '', $rawdata); +} +# Format Data +$lines = explode("\n", $rawdata); +$asterisk = array(); +foreach ($lines as $line) { + list($var,$value) = explode('=', $line); + $asterisk[$var] = $value; +} +# Asterisk stats +$rrd_name = array('app', $name, 'stats', $app_id); +$rrd_def = RrdDefinition::make() + ->addDataset('calls', 'GAUGE', 0, 10000) + ->addDataset('channels', 'GAUGE', 0, 20000) + ->addDataset('sippeers', 'GAUGE', 0, 10000) + ->addDataset('sipmononline', 'GAUGE', 0, 10000) + ->addDataset('sipmonoffline', 'GAUGE', 0, 10000) + ->addDataset('sipunmononline', 'GAUGE', 0, 10000) + ->addDataset('sipunmonoffline', 'GAUGE', 0, 10000); +$fields = array( + 'calls' => $asterisk['Calls'], + 'channels' => $asterisk['Channels'], + 'sipeers' => $asterisk['SipPeers'], + 'sipmononline' => $asterisk['SipMonOnline'], + 'sipmonoffline' => $asterisk['SipMonOffline'], + 'sipunmononline' => $asterisk['SipUnMonOnline'], + 'sipunmonoffline' => $asterisk['SipUnMonOffline'] +); +$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def'); +data_update($device, 'app', $tags, $fields); +update_application($app, $rawdata, $fields); + +unset($lines, $asterisk, $rrd_name, $rrd_def, $fields, $tags, $rawdata);