check_pfstate 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/perl
  2. use strict;
  3. use Getopt::Long;
  4. use vars qw($opt_V $opt_h $opt_P $opt_H $opt_w $opt_c $PROGNAME);
  5. use lib "/usr/local/nagios/libexec" ;
  6. use utils qw(%ERRORS &print_revision &support &usage);
  7. my $remote_user = "root";
  8. my $path_to_ssh = "/usr/bin/ssh";
  9. my $path_to_grep = "/usr/bin/grep";
  10. my $path_to_awk = "/usr/bin/awk";
  11. my $warn = 50000;
  12. my $crit = 60000;
  13. $PROGNAME = "check_pfstate";
  14. $ENV{'PATH'}='';
  15. $ENV{'BASH_ENV'}='';
  16. $ENV{'ENV'}='';
  17. Getopt::Long::Configure('bundling');
  18. GetOptions
  19. ("V" => \$opt_V, "version" => \$opt_V,
  20. "h" => \$opt_h, "help" => \$opt_h,
  21. "H=s" => \$opt_H, "hostname=s" => \$opt_H,
  22. "w=s" => \$opt_w, "warning=s" => \$opt_w,
  23. "c=s" => \$opt_c, "critical=s" => \$opt_c);
  24. if ($opt_V) {
  25. print_revision($PROGNAME,'$Revision$');
  26. exit $ERRORS{'OK'};
  27. }
  28. if ($opt_h) {
  29. print_help();
  30. exit $ERRORS{'OK'};
  31. }
  32. if ($opt_w) {
  33. if ($opt_w =~ /(\d+)/) {
  34. $warn = $1;
  35. } else {
  36. usage("Invalid values: $opt_w\n");
  37. exit $ERRORS{'OK'};
  38. }
  39. }
  40. if ($opt_c) {
  41. if ($opt_c =~ /(\d+)/) {
  42. $crit = $1;
  43. } else {
  44. usage("Invalid values: $opt_c\n");
  45. exit $ERRORS{'OK'};
  46. }
  47. }
  48. ($opt_H) || usage("Host name/address not specified\n");
  49. my $host = $1 if ($opt_H =~ /([-.A-Za-z0-9]+)/);
  50. ($host) || usage("Invalid host: $opt_H\n");
  51. my $result = `$path_to_ssh -l $remote_user $host '/sbin/pfctl -s info' | $path_to_grep entries`;
  52. chomp $result;
  53. $result =~ /(\d+)/;
  54. $result = $1;
  55. print "$result PF state entries\n";
  56. exit $ERRORS{'CRITICAL'} if ($result >= $crit);
  57. exit $ERRORS{'WARNING'} if ($result >= $warn);
  58. exit $ERRORS{'OK'};
  59. sub print_help {
  60. print_revision($PROGNAME,'$Revision$');
  61. print "Copyright (c) 2002 Jason Dixon\n\nThis plugin checks the number of state table entries on a PF-enabled OpenBSD system.\n\n";
  62. print "Usage:\t-H, --hostname=<HOST> [-w, --warning=<WARNING>] [-c, --critical=<CRITICAL>]\n\n\tDefault warning is 50000 and critical is 60000.\n\n";
  63. support();
  64. }