check_failed 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/perl
  2. #======================
  3. # Created May 25, 2000
  4. #======================
  5. # This scripts is for checking for failed root login attempts on
  6. # any machine running AIX which has a failedlogin file in /etc/security
  7. # The purpose is to thwart (good word) any unauthorised people from
  8. # even trying to log in as root. This plugin has been developed for Nagios
  9. # running on AIX.
  10. # Lonny Selinger SpEnTBoY lonny@abyss.za.org
  11. # May
  12. my $server = $ARGV[0];
  13. if (!$ARGV[0]) {
  14. print "You must specify a server to check\n";
  15. print "usage: ./check_failed <Server Name>\n";
  16. exit (-1);
  17. } else {
  18. open (DATE, "/bin/date '+%b %d' |");
  19. while (<DATE>) {
  20. $dline = $_;
  21. @dresults = $dline;
  22. chop $dresults[0];
  23. }
  24. open (SULOG, "rsh $server -l root who /etc/security/failedlogin | grep root |");
  25. while (<SULOG>) {
  26. $line = $_;
  27. @results = split (/\s+/,$line);
  28. if ($line =~ /^root/) {
  29. if (join(' ', @results[2,3]) eq $dresults[0]) {
  30. print "FAILED root login on $dresults[0], node: $ARGV[0] from $results[5]\n";
  31. exit(2);
  32. }
  33. }
  34. }
  35. }
  36. if (join(' ', @results[2,3]) ne $dresults[0]) {
  37. print "No Failed Root Logins on This Node\n";
  38. exit(0);
  39. }
  40. exit(0);
  41. close(SULOG);
  42. close(DATE);