Added --queryfile and --namefromfile parameters

This commit is contained in:
Tómas Edwardsson 2010-09-06 16:18:40 +00:00
parent b27defe0a7
commit 07d6692aa7
1 changed files with 35 additions and 0 deletions

View File

@ -2877,6 +2877,8 @@ my @params = (
"database=s",
"datafile=s",
"waitevent=s",
"namefromfile=s",
"queryfile=s",
"name=s",
"name2=s",
"regexp",
@ -2923,6 +2925,11 @@ if ($commandline{mode} eq "encode") {
exit $ERRORS{OK};
}
if (!exists $commandline{queryfile} || !$commandline{queryfile}) {
$commandline{queryfile} = "/etc/nagios/check_mssql_health-queries";
}
if (exists $commandline{3}) {
$ENV{NRPE_MULTILINESUPPORT} = 1;
}
@ -2978,6 +2985,34 @@ if (exists $commandline{runas}) {
}
}
if (exists $commandline{namefromfile}) {
if (!open QF, "<$commandline{queryfile}") {
print "Unable to open queryfile $commandline{queryfile} param --queryfile\n";
print_help();
exit $ERRORS{OK};
}
my $sql = '';
while (my $l = <QF>) {
# Double chomp if needed
chomp($l) for (0..1);
my ($k, $sql_line) = split(/\s*=\s*/, $l);
if ($k eq $commandline{namefromfile}) {
$sql = $sql_line;
last;
}
}
close QF;
if (!$sql) {
print "Unable to find namefromfile key $commandline{namefromfile} in file $commandline{queryfile}\n";
exit $ERRORS{OK};
}
$commandline{name}=$sql;
}
if ($needs_restart) {
my @newargv = ();
my $runas = undef;