well, they are not public, but I don’t mind if it can help
but, they are very specific, so you may have a hard time to re write them so they can work
anyway, first script is used to just list the data:
[code]#!/usr/bin/perl
use strict;
my $user;
my $password;
$user = “my_login”;
$password = “my_pass”;
my $base = “my_base”;
my $pwd = “$ENV{NAGIOS_HOME}/provisioning/appli”;
chomp($pwd);
open(OUT,">$pwd/data/liste.lst");
my $command = “sqlplus -s $user/$password@$base << EOF 2>&1
set pagesize 0
set space 0
SET LINESIZE 150
SET SERVEROUTPUT ON
SET HEADING OFF
SET VERIFY OFF
SET FEEDBACK OFF
select BASE||’;’||FOLDER||’;’||WORKFLOW||’;’||SEUIL||’;’||TIME||’;’||DOMAIN||’;’||APP_APPLICATION
from XORT_PWMART
where SUP='Y’
ORDER BY FOLDER ASC
;
EOF`”;
my @output = $command
;
print OUT @output;
close(OUT);[/code]
as you can see, we are using sqlplus (too lazy to install DB modules for perl ;)) and this script produces a basic csv file.
From this file, we create the cfg file:
[code]#!/usr/bin/perl
my $pwd = “$ENV{NAGIOS_HOME}/provisioning/appli”;
chomp($pwd);
open(IN,"$pwd/data/liste.lst");
my @lines = ;
close(IN);
my $SEP="####################################################################################";
Initialisations -----------------------------------------------------------------------
my $HOSTS = “$SEP\n# HOSTS DEFINITION\n$SEP\n”;
my $HOSTGROUPS = “$SEP\n# HOST GROUPS DEFINITION\n$SEP\n”;
my $SERVICES = “$SEP\n# SERVICES DEFINITION\n$SEP”;
my $HOSTS_LIST = “”;
foreach my $line (@lines) {
my ($base,$folder,$workflow,$seuil,$duree,$domaine,$app) = split(/;/,$line);
chomp($app);
$HOSTS_LIST .= $workflow.",";
$HOSTS .= "define host{\n\tuse\t\toracle-generic-host\n\thost_name\t$workflow\n\talias\t\tSupSI_Pwmart_".$folder."\n\tcontact_groups\tnetcool-group\n\taddress\t\t$base\n\t}\n";
my $frequence=10;
$seuil++; # on ajoute 1 au seuil, histoire de laisser un peu de marge!
# Statut:
$SERVICES .= "\ndefine service{\n\tuse\t\t\tPwmart-service\n\thost_name\t\t$workflow\n\tservice_description\tStatut\n\tcheck_command\t\tmon_check_pwmart!DUMMY\n\t}";
# Time:
$SERVICES .= "\ndefine service{\n\tuse\t\t\tPwmart-service\n\thost_name\t\t$workflow\n\tservice_description\tTime\n\tcheck_command\t\tmon_check_pwmart!DUMMY\n\t}";
# Duree:
if ( $domaine =~ /GP/ ) {
$SERVICES .= "\ndefine service{\n\tuse\t\t\tPwmart-service\n\thost_name\t\t$workflow\n\tservice_description\tDuree\n\t\n\tcheck_command\t\tmon_check_pwmart!DUMMY\n\t}";
}
}
$HOSTGROUPS .= “define hostgroup{\n\thostgroup_name\tSupSI_Pwmart\n\talias\t\tSupSI_Pwmart\n\tmembers\t\t$HOSTS_LIST\n\t}”;
my $DEF = "################################################################################
COMMANDS DEFINITION
################################################################################
define command{
command_name mon_check_pwmart
command_line $USER1$/mon_check_wflow_Pwmart.pl “$ARG1$” “$ARG2$” “$ARG3$” “$ARG4$” “$ARG5$”
} ; Domaine workflow base seuil seuil duree
################################################################################
SERVICE TEMPLATE DEFINITION
################################################################################
define service{
name Pwmart-service
use service
max_check_attempts 2
normal_check_interval 30
retry_check_interval 2
contact_groups netcool-exploit-group
notification_interval 30
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMLATE
}\n";
Constitution du fichier de conf nagios ------------------------------------------------
open(OUT,">$pwd/data/Pwmart.cfg");
print OUT $DEF."\n";
print OUT $HOSTGROUPS."\n";
print OUT $HOSTS."\n";
print OUT $SERVICES."\n";
close(OUT);
[/code]
it’s a bit messy, but it works (I’ve just erased the comments ('cause they were in french …))
I hope it will help you to write your own scripts quickly.