root / plugins / moblock / moblock_connections @ 17f78427
Historique | Voir | Annoter | Télécharger (1,93 ko)
| 1 |
#!/usr/bin/env ruby |
|---|---|
| 2 |
# |
| 3 |
# Plugin to monitor the number of connections blocked by moblock. |
| 4 |
# |
| 5 |
# Requirements: |
| 6 |
# |
| 7 |
# Moblock up and running with generated log files going to /var/log/moblock |
| 8 |
# |
| 9 |
# Parameters supported: |
| 10 |
# |
| 11 |
# config |
| 12 |
# autoconf |
| 13 |
# |
| 14 |
# Configurable variables |
| 15 |
# |
| 16 |
# logfile - Override default moblock logfile |
| 17 |
# |
| 18 |
# Magic markers |
| 19 |
# |
| 20 |
#%# family=auto |
| 21 |
#%# capabilities=autoconf |
| 22 |
|
| 23 |
# |
| 24 |
# Initialize vars |
| 25 |
# |
| 26 |
$logfile = ENV['logfile'] || "/var/log/moblock.log" |
| 27 |
|
| 28 |
# |
| 29 |
# Configure generated graph |
| 30 |
# |
| 31 |
def config |
| 32 |
puts "graph_args --base 1000 -r --lower-limit 0" |
| 33 |
puts "graph_title Moblock" |
| 34 |
puts "graph_vlabel Blocked Connections" |
| 35 |
puts "graph_category fw" |
| 36 |
puts "graph_info This graph shows the number of connections blocked by Moblock" |
| 37 |
|
| 38 |
puts "blocked_in.label Blocked In" |
| 39 |
puts "blocked_in.draw LINE1" |
| 40 |
puts "blocked_in.info Number of blocked incoming connections" |
| 41 |
puts "blocked_in.type GAUGE" |
| 42 |
|
| 43 |
puts "blocked_out.label Blocked Out" |
| 44 |
puts "blocked_out.draw LINE1" |
| 45 |
puts "blocked_out.info Number of blocked outgoing connections" |
| 46 |
puts "blocked_out.type GAUGE" |
| 47 |
|
| 48 |
puts "blocked_total.label Total Blocked" |
| 49 |
puts "blocked_total.draw LINE1" |
| 50 |
puts "blocked_total.info Total Number of blocked connections" |
| 51 |
puts "blocked_total.type GAUGE" |
| 52 |
end |
| 53 |
|
| 54 |
# |
| 55 |
# Grep moblock logs for stats |
| 56 |
# |
| 57 |
def fetch(debug=false) |
| 58 |
num_in = %x{cat #{$logfile} | grep --extended-regexp 'IN: ' | wc -l}
|
| 59 |
num_out = %x{cat #{$logfile} | grep --extended-regexp 'OUT: ' | wc -l}
|
| 60 |
num_total = num_in.to_i + num_out.to_i |
| 61 |
|
| 62 |
puts "blocked_in.value #{num_in}"
|
| 63 |
puts "blocked_out.value #{num_out}"
|
| 64 |
puts "blocked_total.value #{num_total}"
|
| 65 |
end |
| 66 |
|
| 67 |
# |
| 68 |
# If moblock executable on path then allow autoconfiguration |
| 69 |
# |
| 70 |
def autoconf |
| 71 |
moblock_path = %x{which moblock}
|
| 72 |
if moblock_path.index('moblock')
|
| 73 |
puts "yes" |
| 74 |
else |
| 75 |
puts "no" |
| 76 |
end |
| 77 |
end |
| 78 |
|
| 79 |
# |
| 80 |
# Handle command line args |
| 81 |
# |
| 82 |
case ARGV.first |
| 83 |
when 'config' |
| 84 |
config |
| 85 |
when 'debug' |
| 86 |
fetch true |
| 87 |
when 'autoconf' |
| 88 |
autoconf |
| 89 |
else |
| 90 |
fetch |
| 91 |
end |
