utils.pm.in 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Utility drawer for Nagios plugins.
  2. # $Id$
  3. #
  4. # $Log$
  5. # Revision 1.3 2002/05/10 03:49:22 sghosh
  6. # added programs to autoconf
  7. #
  8. # Revision 1.2 2002/05/08 05:10:35 sghosh
  9. # is_hostname added, update CODES to POSIX
  10. #
  11. #
  12. package utils;
  13. require Exporter;
  14. @ISA = qw(Exporter);
  15. @EXPORT_OK = qw($TIMEOUT %ERRORS &print_revision &support &usage);
  16. #use strict;
  17. #use vars($TIMEOUT %ERRORS);
  18. sub print_revision ($$);
  19. sub usage;
  20. sub support();
  21. sub is_hostname;
  22. ## updated by autoconf
  23. $PATH_TO_RPCINFO = "@PATH_TO_RPCINFO@" ;
  24. $PATH_TO_NTPDATE = "@PATH_TO_NTPDATE@" ;
  25. $PATH_TO_NTPDC = "@PATH_TO_NTPDC@" ;
  26. $PATH_TO_LMSTAT = "@PATH_TO_LMSTAT@" ;
  27. ## common variables
  28. $TIMEOUT = 15;
  29. %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
  30. ## utility subroutines
  31. sub print_revision ($$) {
  32. my $commandName = shift;
  33. my $pluginRevision = shift;
  34. $pluginRevision =~ s/^\$Revision: //;
  35. $pluginRevision =~ s/ \$\s*$//;
  36. print "$commandName (@PACKAGE@ @VERSION@) $pluginRevision\n";
  37. print "@WARRANTY@";
  38. }
  39. sub support () {
  40. my $support='@SUPPORT@';
  41. $support =~ s/@/\@/g;
  42. $support =~ s/\\n/\n/g;
  43. print $support;
  44. }
  45. sub usage {
  46. my $format=shift;
  47. printf($format,@_);
  48. exit $ERRORS{'UNKNOWN'};
  49. }
  50. sub is_hostname {
  51. my $host1 = shift;
  52. if ($host1 && $host1 =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-zA-Z][-a-zA-Z0-9]+(\.[a-zA-Z][-a-zA-Z0-9]+)*)$/) {
  53. return 1;
  54. }else{
  55. return 0;
  56. }
  57. }
  58. 1;