root / plugins / network / pf @ 093708d7
Historique | Voir | Annoter | Télécharger (3,44 ko)
| 1 | 52651cc4 | Gergely Czuczy | #!/bin/sh |
|---|---|---|---|
| 2 | # |
||
| 3 | # OpenBSD's pf(4) monitoring for FreeBSD |
||
| 4 | # 2007, Gergely Czuczy <phoemix@harmless.hu> |
||
| 5 | # |
||
| 6 | # Needs to run as root. |
||
| 7 | # Add "user root" for the [pf] into plugins.conf. |
||
| 8 | # |
||
| 9 | # Options: |
||
| 10 | # - env.do_searches yes: to enable state table search monitoring` |
||
| 11 | # |
||
| 12 | # 0.1 - initial release: |
||
| 13 | # - state table usage |
||
| 14 | # - search rate |
||
| 15 | # - match rate |
||
| 16 | # - state mismatch rate |
||
| 17 | # - blocked packets |
||
| 18 | # - monitoring of labelled rules |
||
| 19 | # |
||
| 20 | # 0.2 - feature improvements: |
||
| 21 | # - Labelled rules for packet count |
||
| 22 | # - OpenBSD compatibility |
||
| 23 | # - Warning and critical on state table |
||
| 24 | # |
||
| 25 | # 0.3 - feature improvements: |
||
| 26 | # - Aggregate rules with the same label |
||
| 27 | # |
||
| 28 | # 0.4 - feature changes: |
||
| 29 | # - State searches are optional. it can shrink others. |
||
| 30 | # - Labelled targets are marked with a leading L |
||
| 31 | # |
||
| 32 | # |
||
| 33 | #%# family=auto |
||
| 34 | #%# capabilities=autoconf |
||
| 35 | acb3839b | Pascal Cabaud | PATH=/bin:/sbin:/usr/bin:/usr/sbin |
| 36 | export PATH |
||
| 37 | 52651cc4 | Gergely Czuczy | |
| 38 | acb3839b | Pascal Cabaud | pfctl="/sbin/pfctl" |
| 39 | 52651cc4 | Gergely Czuczy | |
| 40 | case $1 in |
||
| 41 | config) |
||
| 42 | acb3839b | Pascal Cabaud | echo "graph_title OpenBSD pf statistics" |
| 43 | echo "graph_vlabel Entries per second" |
||
| 44 | echo "graph_scale no" |
||
| 45 | echo "graph_category network" |
||
| 46 | echo "graph_args -l 0" |
||
| 47 | echo "graph_info OpenBSD's pf usage statistics" |
||
| 48 | echo "states.label States" |
||
| 49 | echo "states.type GAUGE" |
||
| 50 | ${pfctl} -sm 2> /dev/null | awk '/states/ {print "states.warning "$4*0.9; print "states.critical "$4*0.95}'
|
||
| 51 | if [ "x${do_searches}" = "xyes" ]; then
|
||
| 52 | echo "searches.label Searches" |
||
| 53 | echo "searches.min 0" |
||
| 54 | echo "searches.type DERIVE" |
||
| 55 | fi |
||
| 56 | echo "matches.label Matches" |
||
| 57 | echo "matches.min 0" |
||
| 58 | echo "matches.type DERIVE" |
||
| 59 | echo "mismatches.label State mismatches" |
||
| 60 | echo "mismatches.min 0" |
||
| 61 | echo "mismatches.type DERIVE" |
||
| 62 | echo "blocks.label Blocked packets" |
||
| 63 | echo "blocks.type DERIVE" |
||
| 64 | echo "blocks.min 0" |
||
| 65 | ${pfctl} -sl 2>/dev/null | awk '{
|
||
| 66 | l=""; |
||
| 67 | for (i=1; i<NF-2; i=i+1) l=l" "$i; |
||
| 68 | sub(/^ /, "", l); |
||
| 69 | f=l; |
||
| 70 | gsub(/[^a-z0-9A-Z]/, "_", f); |
||
| 71 | print f".label L: "l; |
||
| 72 | print f".type DERIVE" |
||
| 73 | print f".min 0"}' |
||
| 74 | exit 0 |
||
| 75 | ;; |
||
| 76 | 52651cc4 | Gergely Czuczy | |
| 77 | autoconf) |
||
| 78 | ostype=`uname -s` |
||
| 79 | acb3839b | Pascal Cabaud | # NetBSD |
| 80 | if [ ${ostype} = "NetBSD" ]; then
|
||
| 81 | # enabled? |
||
| 82 | if [ `${pfctl} -si 2>/dev/null | awk '/^Status:/{print $2}'` != "Enabled" ]; then
|
||
| 83 | echo "no (pf(4) is not enabled, consult pfctl(8))" |
||
| 84 | exit 1 |
||
| 85 | fi |
||
| 86 | # FreeBSD |
||
| 87 | elif [ ${ostype} = "FreeBSD" ]; then
|
||
| 88 | # enabled? |
||
| 89 | if [ `${pfctl} -si 2>/dev/null | awk '/^Status:/{print $2}'` != "Enabled" ]; then
|
||
| 90 | echo "no (pf(4) is not enabled, consult pfctl(8))" |
||
| 91 | exit 1 |
||
| 92 | fi |
||
| 93 | 52651cc4 | Gergely Czuczy | # OpenBSD |
| 94 | elif [ ${ostype} = "OpenBSD" ]; then
|
||
| 95 | acb3839b | Pascal Cabaud | # pf(4) module loaded? |
| 96 | if [ `kldstat -v | grep pf | wc -l` -eq 0 ]; then |
||
| 97 | echo "no (pf(4) is not loaded)" |
||
| 98 | exit 1 |
||
| 99 | fi |
||
| 100 | # enabled? |
||
| 101 | if [ `${pfctl} -si 2>/dev/null | awk '/^Status:/{print $2}'` != "Enabled" ]; then
|
||
| 102 | echo "no (pf(4) is not enabled, consult pfctl(8))" |
||
| 103 | exit 1 |
||
| 104 | fi |
||
| 105 | 52651cc4 | Gergely Czuczy | # Other OSes |
| 106 | else |
||
| 107 | acb3839b | Pascal Cabaud | echo "no (this plugin is not supported on your OS)" |
| 108 | exit 1 |
||
| 109 | 52651cc4 | Gergely Czuczy | fi |
| 110 | echo "yes" |
||
| 111 | exit 0 |
||
| 112 | ;; |
||
| 113 | acb3839b | Pascal Cabaud | |
| 114 | 52651cc4 | Gergely Czuczy | suggest) |
| 115 | exit 0; |
||
| 116 | ;; |
||
| 117 | acb3839b | Pascal Cabaud | |
| 118 | 52651cc4 | Gergely Czuczy | esac |
| 119 | |||
| 120 | # |
||
| 121 | ${pfctl} -si 2>/dev/null | awk '
|
||
| 122 | acb3839b | Pascal Cabaud | /current entries/{print "states.value",$3}
|
| 123 | /searches/{if ( "'${do_searches}'" == "yes" ) print "searches.value",$2}
|
||
| 124 | $1~/^match$/{print "matches.value",$2}
|
||
| 125 | /state-mismatch/{print "mismatches.value",$2}'
|
||
| 126 | 52651cc4 | Gergely Czuczy | ${pfctl} -vsr 2> /dev/null| grep -A 1 ^block | awk 'BEGIN {sum=0}/^[ \t]*\[/{sum=sum+$5} END {print "blocks.value",sum}'
|
| 127 | |||
| 128 | # the labeled ones |
||
| 129 | acb3839b | Pascal Cabaud | ${pfctl} -sl 2>/dev/null | awk '
|
| 130 | BEGIN {
|
||
| 131 | total=0 |
||
| 132 | } |
||
| 133 | {
|
||
| 134 | l=""; |
||
| 135 | for (i=1; i<NF-2; i=i+1) l=l" "$i; |
||
| 136 | sub(/^ /, "", l); |
||
| 137 | f=l; |
||
| 138 | gsub(/[^a-z0-9A-Z]/, "_", f); |
||
| 139 | total=total+1; |
||
| 140 | fields[f]=fields[f]+$(NF-i+2); |
||
| 141 | } |
||
| 142 | END {
|
||
| 143 | if ( total == 0 ) exit 0; |
||
| 144 | for ( k in fields ) print k".value "fields[k] |
||
| 145 | }' |
