utils.pm.in 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Utility drawer for Nagios plugins.
  2. # $Id$
  3. #
  4. # This will be deprecated soon. Please use Nagios::Plugin from CPAN
  5. # for new plugins
  6. package utils;
  7. require Exporter;
  8. @ISA = qw(Exporter);
  9. @EXPORT_OK = qw($TIMEOUT %ERRORS &print_revision &support &usage);
  10. #use strict;
  11. #use vars($TIMEOUT %ERRORS);
  12. sub print_revision ($$);
  13. sub usage;
  14. sub support();
  15. sub is_hostname;
  16. ## updated by autoconf
  17. $PATH_TO_RPCINFO = "@PATH_TO_RPCINFO@" ;
  18. $PATH_TO_LMSTAT = "@PATH_TO_LMSTAT@" ;
  19. $PATH_TO_SMBCLIENT = "@PATH_TO_SMBCLIENT@" ;
  20. $PATH_TO_MAILQ = "@PATH_TO_MAILQ@";
  21. $PATH_TO_QMAIL_QSTAT = "@PATH_TO_QMAIL_QSTAT@";
  22. ## common variables
  23. $TIMEOUT = 15;
  24. %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
  25. ## utility subroutines
  26. sub print_revision ($$) {
  27. my $commandName = shift;
  28. my $pluginRevision = shift;
  29. $pluginRevision =~ s/^\$Revision: //;
  30. $pluginRevision =~ s/ \$\s*$//;
  31. print "$commandName (@PACKAGE@ @VERSION@) $pluginRevision\n";
  32. print "@WARRANTY@";
  33. }
  34. sub support () {
  35. my $support='@SUPPORT@';
  36. $support =~ s/@/\@/g;
  37. $support =~ s/\\n/\n/g;
  38. print $support;
  39. }
  40. sub usage {
  41. my $format=shift;
  42. printf($format,@_);
  43. exit $ERRORS{'UNKNOWN'};
  44. }
  45. sub is_hostname {
  46. my $host1 = shift;
  47. return 0 unless defined $host1;
  48. if ($host1 =~ m/^[\d\.]+$/ && $host1 !~ /\.$/) {
  49. if ($host1 =~ m/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) {
  50. return 1;
  51. } else {
  52. return 0;
  53. }
  54. } elsif ($host1 =~ m/^[a-zA-Z0-9][-a-zA-Z0-9]*(\.[a-zA-Z0-9][-a-zA-Z0-9]*)*\.?$/) {
  55. return 1;
  56. } else {
  57. return 0;
  58. }
  59. }
  60. 1;