utils.pm.in 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # Utility drawer for Nagios plugins.
  2. # $Id$
  3. #
  4. # $Log$
  5. # Revision 1.9 2006/10/19 18:44:53 tonvoon
  6. # Allow hostnames beginning with digits (O'Shaughnessy Evans - 1567390)
  7. #
  8. # Revision 1.8 2006/06/07 14:23:12 seanius
  9. # removed stale references to PATH_TO_NTPFOO, as it's no longer used.
  10. #
  11. # Revision 1.7 2003/04/13 04:25:36 sghosh
  12. # update for check_mailq - qmail support
  13. #
  14. # Revision 1.6 2003/02/03 20:29:55 sghosh
  15. # change ntpdc to ntpq (Jonathan Rozes,Thomas Schimpke, bug-656237 )
  16. #
  17. # Revision 1.5 2002/10/30 05:07:29 sghosh
  18. # monitor mailq
  19. #
  20. # Revision 1.4 2002/05/27 02:01:09 sghosh
  21. # new var - smbclient
  22. #
  23. # Revision 1.3 2002/05/10 03:49:22 sghosh
  24. # added programs to autoconf
  25. #
  26. # Revision 1.2 2002/05/08 05:10:35 sghosh
  27. # is_hostname added, update CODES to POSIX
  28. #
  29. #
  30. package utils;
  31. require Exporter;
  32. @ISA = qw(Exporter);
  33. @EXPORT_OK = qw($TIMEOUT %ERRORS &print_revision &support &usage);
  34. #use strict;
  35. #use vars($TIMEOUT %ERRORS);
  36. sub print_revision ($$);
  37. sub usage;
  38. sub support();
  39. sub is_hostname;
  40. ## updated by autoconf
  41. $PATH_TO_RPCINFO = "@PATH_TO_RPCINFO@" ;
  42. $PATH_TO_LMSTAT = "@PATH_TO_LMSTAT@" ;
  43. $PATH_TO_SMBCLIENT = "@PATH_TO_SMBCLIENT@" ;
  44. $PATH_TO_MAILQ = "@PATH_TO_MAILQ@";
  45. $PATH_TO_QMAIL_QSTAT = "@PATH_TO_QMAIL_QSTAT@";
  46. ## common variables
  47. $TIMEOUT = 15;
  48. %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
  49. ## utility subroutines
  50. sub print_revision ($$) {
  51. my $commandName = shift;
  52. my $pluginRevision = shift;
  53. $pluginRevision =~ s/^\$Revision: //;
  54. $pluginRevision =~ s/ \$\s*$//;
  55. print "$commandName (@PACKAGE@ @VERSION@) $pluginRevision\n";
  56. print "@WARRANTY@";
  57. }
  58. sub support () {
  59. my $support='@SUPPORT@';
  60. $support =~ s/@/\@/g;
  61. $support =~ s/\\n/\n/g;
  62. print $support;
  63. }
  64. sub usage {
  65. my $format=shift;
  66. printf($format,@_);
  67. exit $ERRORS{'UNKNOWN'};
  68. }
  69. sub is_hostname {
  70. my $host1 = shift;
  71. if ($host1 && $host1 =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*)$/) {
  72. return 1;
  73. }else{
  74. return 0;
  75. }
  76. }
  77. 1;