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 <pr_id>`, 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
This commit is contained in:
TheGreatDoc
2018-07-21 21:48:32 +02:00
committed by Neil Lathwood
parent e1118b628a
commit b844dd44c8
8 changed files with 163 additions and 0 deletions

View File

@@ -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 <various options depending on your setup> 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:

View File

@@ -141,6 +141,9 @@ function nicecase($item)
case 'zfs':
return 'ZFS';
case 'asterisk':
return 'Asterisk';
default:
return ucfirst($item);
}

View File

@@ -0,0 +1,14 @@
<?php
require 'includes/graphs/common.inc.php';
$scale_min = 0;
$ds = 'calls';
$colour_area = '9DDA52';
$colour_line = '2EAC6D';
$colour_area_max = 'FFEE99';
$graph_max = 10000;
$unit_text = 'Calls';
$rrd_filename = rrd_name($device['hostname'], array('app', 'asterisk', 'stats', $app['app_id']));
require 'includes/graphs/generic_simplex.inc.php';

View File

@@ -0,0 +1,14 @@
<?php
require 'includes/graphs/common.inc.php';
$scale_min = 0;
$ds = 'channels';
$colour_area = '9DDA52';
$colour_line = '2EAC6D';
$colour_area_max = 'FFEE99';
$graph_max = 20000;
$unit_text = 'Channels';
$rrd_filename = rrd_name($device['hostname'], array('app', 'asterisk', 'stats', $app['app_id']));
require 'includes/graphs/generic_simplex.inc.php';

View File

@@ -0,0 +1,31 @@
<?php
require 'includes/graphs/common.inc.php';
$i = 0;
$scale_min = 0;
$nototal = 1;
$unit_text = 'Peers';
$rrd_filename = rrd_name($device['hostname'], array('app', 'asterisk', 'stats', $app['app_id']));
$astsip_access_array = array(
'sippeers' => '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';

View File

@@ -273,6 +273,11 @@ $graphs['powerdns-dnsdist'] = array(
'rules_stats',
'queries_drop',
);
$graphs['asterisk'] = array(
'calls',
'channels',
'sip',
);
echo '<div class="panel panel-default">';
echo '<div class="panel-heading">';
echo "<span style='font-weight: bold;'>Apps</span> &#187; ";

View File

@@ -0,0 +1,29 @@
<?php
global $config;
$graphs = array(
'asterisk_calls' => '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 '<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">'.$text.'</h3>
</div>
<div class="panel-body">
<div class="row">';
include 'includes/print-graphrow.inc.php';
echo '</div>';
echo '</div>';
echo '</div>';
}

View File

@@ -0,0 +1,45 @@
<?php
use LibreNMS\RRD\RrdDefinition;
$name = 'asterisk';
$app_id = $app['app_id'];
if (!empty($agent_data[$name])) {
$rawdata = $agent_data[$name];
} else {
$options = '-O qv';
$oid = '.1.3.6.1.4.1.8072.1.3.2.4.1.2.8.97.115.116.101.114.105.115.107';
$rawdata = snmp_walk($device, $oid, $options);
$rawdata = str_replace("<<<asterisk>>>\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);