# Nagios Business Process View and Nagios Business Process Analysis # Copyright (C) 2003-2010 Sparda-Datenverarbeitung eG, Nuernberg, Germany # Bernd Stroessreuther # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA package nagiosBp; use lib ('@libdir@'); use Exporter; use strict; use bsutils; use settings; our $settings = getSettings(); our %i18n; our @ISA = qw(Exporter); our @EXPORT = qw(getBPs read_language_file get_lang_string getAvaiableLanguages and listAllComponentsOf); #parse nagios-bp.conf (our own config file) # parameter 1: the path of nagios-bp.conf file to be used # parameter 2: a reference to the hardstates hash # this hash is extended by this function (states of business processes are added) # parameter 3: "true" or "false", should external scripts be executed # defaults to "true" # returns: hash reference with descriptions of all business processes # returns: hash reference with priorities of all business processes # returns: hash reference with the outputs of all external-info scripts # empty if parameter 3 is "false" # returns: hash reference with all info-urls # returns: hash reference with the formula for each business process sub getBPs() { my $nagios_bp_conf = shift; my $hardstates = shift; my $execute_external_scripts = shift || "true"; my (@fields, @fields_state, $in, $formula, $num_of_operators, $result, %display_status, %display, %script_out, %info_url, %components, $description, $i, $min_ok, $name_ext, $name, $script, $status, $url, $var); open (IN, "<$nagios_bp_conf") or nagdie("unable to read $nagios_bp_conf"); while ($in = ) { # filter comments (starting with #) and blank lines if ($in !~ m/^#/ && $in !~ m/^ *$/) { #print "$in"; # for all display definitions (lines starting with "display") if ($in =~ m/^display/) { $in = substr($in, 8); ($status, $name, $description) = split(/;/, $in); chomp($description); $display{$name} = $description; $display_status{$name} = $status; #print "name: $name description: $description\n"; } # for all external_info definitions (lines starting with "external_info") elsif ($in =~ m/^external_info/) { if ($execute_external_scripts ne "false") { $in = substr($in, 14); ($name_ext, $script) = split(/;/, $in); chomp($script); open(SCRIPT, "$script |") or die "unable to execute script $script"; $script_out{$name_ext} =