You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.9 KiB

  1. #!/usr/bin/perl -w
  2. use strict;
  3. use English;
  4. use Getopt::Long;
  5. #use File::stat;
  6. sub print_help ();
  7. sub print_usage ();
  8. sub check_username ();
  9. my ($opt_z, $opt_h, $opt_b, $opt_u);
  10. my ($result, $message, @failed_services);
  11. my $PROGNAME="check_zmstatus";
  12. #default values
  13. $opt_z='/opt/zimbra/bin/zmcontrol';
  14. $opt_u='zimbra';
  15. Getopt::Long::Configure('bundling');
  16. GetOptions(
  17. "h" => \$opt_h, "help" => \$opt_h,
  18. "u=s" => \$opt_u, "username" => \$opt_u,
  19. "b=s" => \$opt_z, "binary" => \$opt_z);
  20. if ($opt_h) {
  21. print_help();
  22. exit;
  23. }
  24. $opt_z = shift unless ($opt_z);
  25. # Check that binary exists
  26. unless (-e $opt_z) {
  27. print "CRITICAL: ZMStatus not found - $opt_z\n";
  28. exit 2;
  29. }
  30. # open "zmcontrol status" command
  31. open(ZMCONTROL, "sudo -u ".$opt_u." $opt_z status |") || die('zmcontrol not found');
  32. my @zmcontent = <ZMCONTROL>;
  33. close(ZMCONTROL);
  34. my $i;
  35. # parse every line exept the first
  36. for ($i=1; $i<@zmcontent;$i++) {
  37. if ($zmcontent[$i] =~ m/\s([a-zA-Z ]+)\s{2,}(\w+)/g) {
  38. if ($2 ne "Running") {
  39. push @failed_services, $1;
  40. }
  41. }
  42. }
  43. # $i tells if services where checked
  44. if (( @failed_services == 0 ) && ($i > 5)) {
  45. print "OK: every service is running fine\n";
  46. exit 0; # OK
  47. } else {
  48. print "Critical: " . join(',', @failed_services) . " not running";
  49. exit 2; # Error
  50. }
  51. sub print_usage () {
  52. print "Usage:\n";
  53. print " $PROGNAME [-u username] [-b zmstatuspath]\n";
  54. print " $PROGNAME [-h | --help]\n";
  55. }
  56. sub print_help () {
  57. print "Copyright (c) 2008 Andreas Roth\n\n";
  58. print_usage();
  59. print "\n";
  60. print " <username> username for zimbrauser - be aware of setting up sudo before (default: zimbra)\n";
  61. print " <zmstatuspath> Path where zmcontrol command is found (default: /opt/zimbra/bin/zmcontrol)\n";
  62. print "\n";
  63. }