2017-02-24 11:50:33 -06:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use LibreNMS\RRD\RrdDefinition;
|
|
|
|
|
|
2017-03-29 22:54:02 -05:00
|
|
|
echo "fail2ban";
|
|
|
|
|
|
2017-02-24 11:50:33 -06:00
|
|
|
$name = 'fail2ban';
|
|
|
|
|
$app_id = $app['app_id'];
|
|
|
|
|
|
|
|
|
|
$options = '-O qv';
|
2017-03-31 04:01:40 +01:00
|
|
|
$oid = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.8.102.97.105.108.50.98.97.110';
|
|
|
|
|
$f2b = snmp_walk($device, $oid, $options);
|
2017-05-04 19:22:13 +01:00
|
|
|
$f2b = trim($f2b, '"');
|
2017-02-24 11:50:33 -06:00
|
|
|
|
2017-12-06 16:13:10 -06:00
|
|
|
$metrics = array();
|
2017-05-04 19:22:13 +01:00
|
|
|
$bannedStuff = explode("\n", $f2b);
|
2017-02-24 11:50:33 -06:00
|
|
|
|
2017-03-29 22:54:02 -05:00
|
|
|
$total_banned=$bannedStuff[0];
|
2017-02-24 11:50:33 -06:00
|
|
|
|
|
|
|
|
$rrd_name = array('app', $name, $app_id);
|
|
|
|
|
$rrd_def = RrdDefinition::make()
|
|
|
|
|
->addDataset('banned', 'GAUGE', 0)
|
|
|
|
|
->addDataset('firewalled', 'GAUGE', 0);
|
|
|
|
|
|
2017-12-30 05:39:20 -06:00
|
|
|
|
2017-02-24 11:50:33 -06:00
|
|
|
$fields = array(
|
2017-03-29 22:54:02 -05:00
|
|
|
'banned' =>$total_banned,
|
2017-12-30 05:39:20 -06:00
|
|
|
'firewalled'=>'U',
|
2017-02-24 11:50:33 -06:00
|
|
|
);
|
2017-12-06 16:13:10 -06:00
|
|
|
$metrics['total'] = $fields;
|
2017-02-24 11:50:33 -06:00
|
|
|
|
|
|
|
|
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
|
|
|
|
data_update($device, 'app', $tags, $fields);
|
|
|
|
|
|
2017-12-30 05:39:20 -06:00
|
|
|
$int=1;
|
2017-03-29 22:54:02 -05:00
|
|
|
$jails=array();
|
|
|
|
|
|
2017-02-24 11:50:33 -06:00
|
|
|
while (isset($bannedStuff[$int])) {
|
2017-03-29 22:54:02 -05:00
|
|
|
list($jail, $banned) = explode(" ", $bannedStuff[$int]);
|
2017-02-24 11:50:33 -06:00
|
|
|
|
|
|
|
|
if (isset($jail) && isset($banned)) {
|
2017-03-29 22:54:02 -05:00
|
|
|
$jails[] = $jail;
|
|
|
|
|
|
2017-02-24 11:50:33 -06:00
|
|
|
$rrd_name = array('app', $name, $app_id, $jail);
|
|
|
|
|
$rrd_def = RrdDefinition::make()->addDataset('banned', 'GAUGE', 0);
|
2017-03-29 22:54:02 -05:00
|
|
|
$fields = array('banned' => $banned);
|
2017-02-24 11:50:33 -06:00
|
|
|
|
2017-12-06 16:13:10 -06:00
|
|
|
$metrics["jail_$jail"] = $fields;
|
2017-02-24 11:50:33 -06:00
|
|
|
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
|
|
|
|
data_update($device, 'app', $tags, $fields);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$int++;
|
|
|
|
|
}
|
2017-03-29 22:54:02 -05:00
|
|
|
|
2017-12-06 16:13:10 -06:00
|
|
|
update_application($app, $f2b, $metrics);
|
|
|
|
|
|
2017-03-29 22:54:02 -05:00
|
|
|
//
|
|
|
|
|
// component processing for fail2ban
|
|
|
|
|
//
|
|
|
|
|
$device_id=$device['device_id'];
|
|
|
|
|
|
|
|
|
|
$options=array(
|
|
|
|
|
'filter' => array(
|
|
|
|
|
'type' => array('=', 'fail2ban'),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$component = new LibreNMS\Component();
|
|
|
|
|
$f2b_components = $component->getComponents($device_id, $options);
|
|
|
|
|
|
|
|
|
|
// if no jails, delete fail2ban components
|
|
|
|
|
if (empty($jails)) {
|
|
|
|
|
if (isset($f2b_components[$device_id])) {
|
|
|
|
|
foreach ($f2b_components[$device_id] as $component_id => $_unused) {
|
|
|
|
|
$component->deleteComponent($component_id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (isset($f2b_components[$device_id])) {
|
|
|
|
|
$f2bc = $f2b_components[$device_id];
|
|
|
|
|
} else {
|
|
|
|
|
$f2bc = $component->createComponent($device_id, 'fail2ban');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$id = $component->getFirstComponentID($f2bc);
|
|
|
|
|
$f2bc[$id]['label'] = 'Fail2ban Jails';
|
|
|
|
|
$f2bc[$id]['jails'] = json_encode($jails);
|
|
|
|
|
|
|
|
|
|
$component->setComponentPrefs($device_id, $f2bc);
|
|
|
|
|
}
|