root / plugins / network / pf_bytes @ dd4afac8
Historique | Voir | Annoter | Télécharger (1,53 ko)
| 1 | d793a51a | immerda admin team | #!/bin/sh |
|---|---|---|---|
| 2 | # |
||
| 3 | # OpenBSD's pf(4) monitoring for OpenBSD |
||
| 4 | # 2007, Originally by Gergely Czuczy <phoemix@harmless.hu> |
||
| 5 | # for FreeBSD systems. Ported and splitted by the |
||
| 6 | # immerda admin team admin(at)immerda.ch |
||
| 7 | # this version is adapted for openbsd and is only tested on |
||
| 8 | # openbsd systems. |
||
| 9 | # |
||
| 10 | # Needs to run as root. |
||
| 11 | # Add "user root" for the [pf] into plugins.conf. |
||
| 12 | # |
||
| 13 | #%# family=auto |
||
| 14 | #%# capabilities=autoconf |
||
| 15 | |||
| 16 | pfctl='/sbin/pfctl' |
||
| 17 | |||
| 18 | case $1 in |
||
| 19 | config) |
||
| 20 | cat <<EOF |
||
| 21 | graph_title OpenBSD pf label bytes statistics |
||
| 22 | graph_vlabel bytes per second |
||
| 23 | graph_scale no |
||
| 24 | graph_category network |
||
| 25 | graph_args -l 0 |
||
| 26 | graph_info OpenBSD's pf label bytes usage statistics |
||
| 27 | EOF |
||
| 28 | pfctl -sl | awk ' |
||
| 29 | BEGIN {
|
||
| 30 | total=0 |
||
| 31 | } |
||
| 32 | {
|
||
| 33 | l=$1; |
||
| 34 | f_bytes=l; |
||
| 35 | gsub(/[^a-z0-9A-Z]/, "_", f_bytes); |
||
| 36 | fields[f_bytes]=l; |
||
| 37 | total=total+1 |
||
| 38 | } |
||
| 39 | END {
|
||
| 40 | if ( total == 0 ) exit 0; |
||
| 41 | for ( k in fields ) print k".label "fields[k]"\n"k".type DERIVE\n"k".min 0" |
||
| 42 | }' |
||
| 43 | |||
| 44 | exit 0 |
||
| 45 | ;; |
||
| 46 | autoconf) |
||
| 47 | # FreeBSD |
||
| 48 | ostype=`uname -s` |
||
| 49 | # OpenBSD |
||
| 50 | if [ ${ostype} = "OpenBSD" ]; then
|
||
| 51 | # enabled? |
||
| 52 | if [ `pfctl -si 2>/dev/null | awk '/^Status:/{print $2}'` != "Enabled" ]; then
|
||
| 53 | echo "no (pf(4) is not enabled, consult pfctl(8)" |
||
| 54 | exit 1 |
||
| 55 | fi |
||
| 56 | # Other OSes |
||
| 57 | else |
||
| 58 | echo "no (this plugin is not supported on your OS)" |
||
| 59 | exit 1 |
||
| 60 | fi |
||
| 61 | echo "yes" |
||
| 62 | exit 0 |
||
| 63 | ;; |
||
| 64 | suggest) |
||
| 65 | exit 0; |
||
| 66 | ;; |
||
| 67 | esac |
||
| 68 | |||
| 69 | sudo pfctl -sl | awk ' |
||
| 70 | BEGIN {
|
||
| 71 | total=0 |
||
| 72 | } |
||
| 73 | {
|
||
| 74 | l=$1; |
||
| 75 | f_bytes=l; |
||
| 76 | gsub(/[^a-z0-9A-Z]/, "_", f_bytes); |
||
| 77 | total=total+1; |
||
| 78 | fields[f_bytes]=fields[f_bytes]+$4; |
||
| 79 | } |
||
| 80 | END {
|
||
| 81 | if ( total == 0 ) exit 0; |
||
| 82 | for ( k in fields ) print k".value "fields[k] |
||
| 83 | }' |
||
| 84 |
