utils.pm.in 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Utility drawer for Nagios plugins.
  2. # $Id$
  3. #
  4. # $Log$
  5. # Revision 1.2 2002/05/08 05:10:35 sghosh
  6. # is_hostname added, update CODES to POSIX
  7. #
  8. #
  9. package utils;
  10. require Exporter;
  11. @ISA = qw(Exporter);
  12. @EXPORT_OK = qw($TIMEOUT %ERRORS &print_revision &support &usage);
  13. #use strict;
  14. #use vars($TIMEOUT %ERRORS);
  15. sub print_revision ($$);
  16. sub usage;
  17. sub support();
  18. sub is_hostname;
  19. $TIMEOUT = 15;
  20. %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
  21. sub print_revision ($$) {
  22. my $commandName = shift;
  23. my $pluginRevision = shift;
  24. $pluginRevision =~ s/^\$Revision: //;
  25. $pluginRevision =~ s/ \$\s*$//;
  26. print "$commandName (@PACKAGE@ @VERSION@) $pluginRevision\n";
  27. print "@WARRANTY@";
  28. }
  29. sub support () {
  30. my $support='@SUPPORT@';
  31. $support =~ s/@/\@/g;
  32. $support =~ s/\\n/\n/g;
  33. print $support;
  34. }
  35. sub usage {
  36. my $format=shift;
  37. printf($format,@_);
  38. exit $ERRORS{'UNKNOWN'};
  39. }
  40. sub is_hostname {
  41. my $host1 = shift;
  42. 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]+)*)$/) {
  43. return 1;
  44. }else{
  45. return 0;
  46. }
  47. }
  48. 1;