File nagtrap-check_snmptraps-use_config.patch of Package nagtrap

Index: nagtrap-1.5.0/plugin/check_snmptraps.pl.in
===================================================================
--- nagtrap-1.5.0.orig/plugin/check_snmptraps.pl.in
+++ nagtrap-1.5.0/plugin/check_snmptraps.pl.in
@@ -33,7 +33,7 @@ my $enableDebug = "0";
 my $debugLogFile = "@logdir@/check_snmptraps.log";
 
 # ==================== Variables ====================
-my ($opt_V, $opt_h, $opt_C, $opt_H, $opt_O, $opt_t, $opt_r, $opt_S, $opt_m, $opt_w, $opt_c, $opt_u);
+my ($opt_V, $opt_f, $opt_h, $opt_C, $opt_H, $opt_O, $opt_t, $opt_r, $opt_S, $opt_m, $opt_w, $opt_c, $opt_u);
 my $PROGNAME = "check_snmptraps.pl";
 my $version = "1.3.2";
 my $queryCategory = "";
@@ -97,6 +97,8 @@ sub print_usage (){
    printf "     seconds before the plugin times out (default=$TIMEOUT)\n";
    printf "   -V (--version)\n";
    printf "     Plugin version\n";
+   printf "   -f (--configfile)\n";
+   printf "      Use Database connection parameters stored in this file\n";
    printf "   -h (--help)\n";
    printf "     Print this help \n";
 }
@@ -157,6 +159,7 @@ GetOptions(
    "m"   => \$opt_m, "message"  => \$opt_m,
    "t=i" => \$opt_t, "timeout"  => \$opt_t,
    "V"   => \$opt_V, "version"  => \$opt_V,
+   "f=s" => \$opt_f, "configfile=s" => \$opt_f,
    "h"   => \$opt_h, "help"     => \$opt_h);
 
 # ==================== Main ====================
@@ -193,6 +196,16 @@ if (! $opt_H) {
    exit $ERRORS{'UNKNOWN'};
 }
 
+if (defined($opt_f) && -f $opt_f){
+   use Config::Simple;
+   my $cfg = new Config::Simple("$opt_f");
+   $dbHost  = $cfg->{'_DATA'}{'default'}{'MYSQL_HOST'}[0] if (defined($cfg->{'_DATA'}{'default'}{'MYSQL_HOST'}[0]));
+   $dbName  = $cfg->{'_DATA'}{'default'}{'MYSQL_DB'}[0] if (defined($cfg->{'_DATA'}{'default'}{'MYSQL_DB'}[0]));
+   $dbUser  = $cfg->{'_DATA'}{'default'}{'MYSQL_USER'}[0] if (defined($cfg->{'_DATA'}{'default'}{'MYSQL_USER'}[0]));
+   $dbPass  = $cfg->{'_DATA'}{'default'}{'MYSQL_PASS'}[0] if (defined($cfg->{'_DATA'}{'default'}{'MYSQL_PASS'}[0]));
+   $dbTable = $cfg->{'_DATA'}{'default'}{'MYSQL_TABLE'}[0] if (defined($cfg->{'_DATA'}{'default'}{'MYSQL_TABLE'}[0]));
+}
+
 # Create query for search string in trap messages
 if ($opt_S) {
    $querySearchString = "AND LOCATE('$opt_S',formatline)>0";
openSUSE Build Service is sponsored by