Files
librenms-librenms/includes/polling/applications/fail2ban.inc.php
VVelox acd11955d2 use components for fail2ban jails list (#6221)
* add get_fail2ban_jails functions

* now do component stuff for fail2ban for tracking jails

* now use get_fail2ban_jails for getting a list of jails

* readd the accidentally deleted update app bit

* white space cleanup

* Update fail2ban component code

* remove unneeded variable
2017-03-29 22:54:02 -05:00

88 lines
2.3 KiB
PHP

<?php
use LibreNMS\RRD\RrdDefinition;
echo "fail2ban";
$name = 'fail2ban';
$app_id = $app['app_id'];
$options = '-O qv';
$mib = 'NET-SNMP-EXTEND-MIB';
$oid = 'nsExtendOutputFull.8.102.97.105.108.50.98.97.110';
$new_component = snmp_walk($device, $oid, $options, $mib);
update_application($app, $new_component);
$bannedStuff = explode("\n", $new_component);
$total_banned=$bannedStuff[0];
$firewalled=$bannedStuff[1];
$rrd_name = array('app', $name, $app_id);
$rrd_def = RrdDefinition::make()
->addDataset('banned', 'GAUGE', 0)
->addDataset('firewalled', 'GAUGE', 0);
$fields = array(
'banned' =>$total_banned,
'firewalled' => $firewalled,
);
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
data_update($device, 'app', $tags, $fields);
$int=2;
$jails=array();
while (isset($bannedStuff[$int])) {
list($jail, $banned) = explode(" ", $bannedStuff[$int]);
if (isset($jail) && isset($banned)) {
$jails[] = $jail;
$rrd_name = array('app', $name, $app_id, $jail);
$rrd_def = RrdDefinition::make()->addDataset('banned', 'GAUGE', 0);
$fields = array('banned' => $banned);
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
data_update($device, 'app', $tags, $fields);
}
$int++;
}
//
// 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);
}