aboutsummaryrefslogtreecommitdiff
path: root/plugins-scripts/utils.pm.in
blob: 05735eb4f7056343f0597b44bf4fd2868d8f3b3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Utility drawer for Nagios plugins.
# $Id$
#
# $Log$
# Revision 1.5  2002/10/30 05:07:29  sghosh
# monitor mailq
#
# Revision 1.4  2002/05/27 02:01:09  sghosh
#  new var - smbclient
#
# Revision 1.3  2002/05/10 03:49:22  sghosh
# added programs to autoconf
#
# Revision 1.2  2002/05/08 05:10:35  sghosh
#  is_hostname added, update CODES to POSIX
#
# 
package utils;

require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw($TIMEOUT %ERRORS &print_revision &support &usage);

#use strict;
#use vars($TIMEOUT %ERRORS);
sub print_revision ($$);
sub usage;
sub support();
sub is_hostname;

## updated by autoconf
$PATH_TO_RPCINFO = "@PATH_TO_RPCINFO@" ;
$PATH_TO_NTPDATE = "@PATH_TO_NTPDATE@" ;
$PATH_TO_NTPDC   = "@PATH_TO_NTPDC@" ;
$PATH_TO_LMSTAT  = "@PATH_TO_LMSTAT@" ;
$PATH_TO_SMBCLIENT = "@PATH_TO_SMBCLIENT@" ;
$PATH_TO_MAILQ   = "@PATH_TO_MAILQ@";

## common variables
$TIMEOUT = 15;
%ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);

## utility subroutines
sub print_revision ($$) {
	my $commandName = shift;
	my $pluginRevision = shift;
	$pluginRevision =~ s/^\$Revision: //;
	$pluginRevision =~ s/ \$\s*$//;
	print "$commandName (@PACKAGE@ @VERSION@) $pluginRevision\n";
	print "@WARRANTY@";
}

sub support () {
	my $support='@SUPPORT@';
	$support =~ s/@/\@/g;
	$support =~ s/\\n/\n/g;
	print $support;
}

sub usage {
	my $format=shift;
	printf($format,@_);
	exit $ERRORS{'UNKNOWN'};
}

sub is_hostname {
	my $host1 = shift;
	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]+)*)$/) {
		return 1;
	}else{
		return 0;
	}
}

1;