refactor: Fail2ban polling update and dropping of the FW checking (#7936)

* Update polling and drop the firewalled bit.

Since fail2ban on FreeBSD has moved to using anchors, the previous
issue of it dreking all over its self is no longer a problem.

And AFAIK it has never been an issue on Linux.

This also makes this script more cross platform as well instead.

* change the name of the graph of the total banned so people don't have to remove old file

* go back to the original RRD and just shove U into the no longer data area
This commit is contained in:
VVelox
2017-12-30 05:39:20 -06:00
committed by Neil Lathwood
parent 7d0ad5c4ef
commit 0e13e77c5f
3 changed files with 22 additions and 13 deletions

View File

@@ -215,21 +215,36 @@ snmp ALL=(ALL) NOPASSWD: /etc/snmp/exim-stats.sh, /usr/bin/exim*
extend fail2ban /etc/snmp/fail2ban
```
4: Edit /etc/snmp/fail2ban to match the firewall table you are using on your system. You should be good if you are using the defaults. Also make sure that the cache variable is properly set if you wish to use caching. The directory it exists in, needs to exist as well. To make sure it is working with out issue, run '/etc/snmp/fail2ban -u' and make sure it runs with out producing any errors.
If you want to use the cache, it is as below, by using the -c switch.
```
extend fail2ban /etc/snmp/fail2ban -c
```
If you want to use the cache and update it if needed, this can by using the -c and -U switches.
```
extend fail2ban /etc/snmp/fail2ban -c -U
```
If you need to specify a custom location for the fail2ban-client, that can be done via the -f switch.
If not specified, "/usr/bin/env fail2ban-client" is used.
```
extend fail2ban /etc/snmp/fail2ban -f /foo/bin/fail2ban-client
```
5: Restart snmpd on your host
6: If you wish to use caching, add the following to /etc/crontab and restart cron.
6: If you wish to use caching, add the following to /etc/crontab and restart cron.
```
*/3 * * * * root /etc/snmp/fail2ban -u
```
7: Restart or reload cron on your system.
In regards to the totals graphed there are two variables banned and firewalled. Firewalled is a count of banned entries the firewall for fail2ban and banned is the currently banned total from fail2ban-client. Both are graphed as the total will diverge with some configurations when fail2ban fails to see if a IP is in more than one jail when unbanning it. This is most likely to happen when the recidive is in use.
If you have more than a few jails configured, you may need to use caching as each jail needs to be polled and fail2ban-client can't do so in a timely manner for than a few. This can result in failure of other SNMP information being polled.
For additional details of the switches, please see the POD in the script it self at the top.
### FreeBSD NFS Client
#### SNMP Extend

View File

@@ -21,12 +21,6 @@ if (is_file($rrd_filename)) {
'ds' => 'banned',
'colour' => '582A72'
),
array(
'filename' => $rrd_filename,
'descr' => 'Firewalled',
'ds' => 'firewalled',
'colour' => '28774F'
)
);
} else {
echo "file missing: $rrd_filename";

View File

@@ -16,23 +16,23 @@ $metrics = array();
$bannedStuff = explode("\n", $f2b);
$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,
'firewalled'=>'U',
);
$metrics['total'] = $fields;
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
data_update($device, 'app', $tags, $fields);
$int=2;
$int=1;
$jails=array();
while (isset($bannedStuff[$int])) {