Code

Updated POST handling for mail shared folders.
[gosa.git] / gosa-plugins / nagios / contrib / goNagios.pl
index 754681dbc3f00cc1febeb57770341759e99abbd8..de04ad09bcc6c1eafb5d124084a6df382ee8f2d6 100755 (executable)
@@ -3,6 +3,7 @@
 
 # Copyright (C) 2005 Guillaume Delecourt <guillaume.delecourt@opensides.be>
 # Copyright (C) 2005 Vincent Senave <vincent.senave@opensides.be>
+# Copyright (C) 2005-2009 Benoit Mortier <benoit.mortier@opensides.be>
 #
 #
 # This program is free software; you can redistribute it and/or modify
@@ -52,9 +53,9 @@ my ($i,$file,$ldap,@nagiosmail,
        $usercontact,$members,@contactname,@nagiosalias,$j,@entries
 );
 
-# Les parametres de connexion proviennent du fichier smbldap-bind.conf
-my $gosa_bind_conf="/etc/gosa_bind.conf";
-my $gosa_ldap_conf="/etc/gosaldap.conf";
+# The connexion parameters are in gosa_bind.conf
+my $gosa_bind_conf="/etc/gosa/gosa_bind.conf";
+my $gosa_ldap_conf="/etc/gosa/nagios_ldap.conf";
 my %config_bind = &read_conf($gosa_bind_conf);
 my %config = &read_conf($gosa_ldap_conf);
 
@@ -90,7 +91,7 @@ my $password=$config_bind{masterPw};
 
        
 
-       #Partie pour l'objectClass NAgios Contact
+       #Part of the ObjectClass NAgios Contact
        $mesg = $ldap->search(filter=>"(&(objectClass~=nagiosContact))", base=>$peopleou,scope=>$scope);
        @entries = $mesg->entries;
        $i=0;
@@ -109,13 +110,23 @@ my $password=$config_bind{masterPw};
        $nb_user=$i;
                
                
-       #Partie pour l'objectClass NAgios Group
+       #Part of the ObjectClass NAgios Group
        $mesg = $ldap->search(filter=>"(&(objectClass~=nagiosContactGroup))", base=>$groupeou,scope=>$scope);
        @entries = $mesg->entries;
        $i=0;
        foreach $entry (@entries) {
        $stdout.="\nGroupe $i : \nName\t\t";$groupname[$i]=$entry->get_value('cn');$stdout.=$groupname[$i];
-       $stdout.="\n\n\talias:\t\t";$groupdescription[$i]=$entry->get_value('description');$stdout.=$groupdescription[$i];
+
+       $stdout.="\n\n\talias:\t\t";
+       $groupdescription[$i]=$entry->get_value('description');
+
+       if(defined($groupdescription[$i])) { 
+               $stdout.=$groupdescription[$i];
+       } else { 
+               # We need a valid description entry, so we'll just use the groupname
+               $stdout.=$groupname[$i];
+       }
+
        $stdout.="\n\tmembers:\t";
        $j=0;
        foreach $members($entry->get_value('memberUid'))
@@ -129,16 +140,14 @@ my $password=$config_bind{masterPw};
        }
        $nb_groupe=$i;
 
-               $userlist1.=$admindef;
-
-       #Partie pour l'objectClass NagiosAuth
+       #Part of the ObjectClass NagiosAuth
        $stdout.="\n\n\n\n\nAuthorization for the different Information in Nagios\n"."-" x 53;$stdout.="\n";
        $mesg = $ldap->search(filter=>"(&(objectClass~=nagiosAuth)(AuthorizedSystemInformation~=checked))", base=>$peopleou,scope=>$scope);
        @entries = $mesg->entries;
        $stdout.="\nSystem infos :\t\t";
        foreach $entry (@entries) {
        $stdout.= $entry->get_value('uid')."\t";
-       $userlist1.=$entry->get_value('uid')."  ,";
+       $userlist1.=$entry->get_value('uid').",";
        }
        $userlist1.=$admindef;
 
@@ -147,7 +156,7 @@ my $password=$config_bind{masterPw};
        $stdout.="\nConfiguration infos :\t";
        foreach $entry (@entries) {
        $stdout.= $entry->get_value('uid')."\t";
-       $userlist2.=$entry->get_value('uid')." , ";
+       $userlist2.=$entry->get_value('uid').",";
        }
        $userlist2.=$admindef;
 
@@ -156,7 +165,7 @@ my $password=$config_bind{masterPw};
        $stdout.="\nSystem commands : \t";
        foreach $entry (@entries) {
        $stdout.= $entry->get_value('uid')."\t";
-       $userlist3.=$entry->get_value('uid')." , ";
+       $userlist3.=$entry->get_value('uid').",";
        }
        $userlist3.=$admindef;
 
@@ -165,7 +174,7 @@ my $password=$config_bind{masterPw};
        $stdout.="\nAll services :\t\t";
        foreach $entry (@entries) {
        $stdout.= $entry->get_value('uid')."\t";
-       $userlist4.=$entry->get_value('uid')." ,";
+       $userlist4.=$entry->get_value('uid').",";
        }
        $userlist4.=$admindef;
 
@@ -216,9 +225,9 @@ sub modiffile_contact()
 {
        $file=$_[0];
        my $text="";
-       open(FH,"$file") || die "Probleme d'ouverture du fichier $file";
+       open(FH,"$file") || die "Can't open file $file";
        $stdout.="\n\n"; $stdout.=" "x10;$stdout.="-"x25;$stdout.=" "x10;
-       $stdout.="\n\n$nb_user utilisateur(s) ajouté(s) dans le fichier $file\n";
+       $stdout.="\n\n$nb_user user(s) added in file $file\n";
        for($i=0;$i<$nb_user;$i++)
        {
                $text.="\n\ndefine contact{\n";
@@ -228,11 +237,13 @@ sub modiffile_contact()
                $text.="\n\thost_notification_options \t".$hostnotificationoptions[$i];
                $text.="\n\tservice_notification_period \t".$servicenotificationperiod[$i];
                $text.="\n\tservice_notification_options \t".$servicenotificationoptions[$i];
+               $text.="\n\tservice_notification_commands \t".$config{service_notification_commands};
+               $text.="\n\thost_notification_commands \t".$config{host_notification_commands};
                $text.="\n\temail \t\t\t\t".$nagiosmail[$i];
                $text.="\n}\n\n";
        }
        close(FH);
-       open(FH,"> $file") || die "Probleme d'ouverture du fichier $file";
+       open(FH,"> $file") || die "Can't open file $file";
        print  FH "$text";
        close(FH);
        
@@ -244,25 +255,34 @@ sub modiffile_group()
        $text="";
        $j=0;
        $i=0;
-       open(FH,"$file") || die "Probleme d'ouverture du fichier $file";
+       open(FH,"$file") || die "Can't open $file";
        $stdout.="\n\n"; $stdout.=" "x10;$stdout.="-"x25;$stdout.=" "x10;
-       $stdout.="\n\n$nb_groupe groupe(s) ajouté(s) dans le fichier $file\n";
+       $stdout.="\n\n$nb_groupe group(s) added in file $file\n";
        for($i=0;$i<$nb_groupe;$i++)
        {
-               $text.="\n\ndefine contact{\n";
+               $text.="\n\ndefine contactgroup{\n";
                $text.="\n\tcontactgroup_name \t".$groupname[$i];
-               $text.="\n\talias \t\t\t".$groupdescription[$i];
+               if(defined($groupdescription[$i])) {
+                       $text.="\n\talias \t\t\t".$groupdescription[$i];
+               } else { 
+                       # We need a valid alias entry, so we'll just use the groupname
+                       $text.="\n\talias \t\t\t".$groupname[$i]; 
+               }
                $text.="\n\tmembers \t\t";
                while(defined($groupmembers[$i][$j]))
                {
-                       $text.=$groupmembers[$i][$j]." ";
+                       $text.=$groupmembers[$i][$j];
                        $j++;
+                       
+                       if(defined($groupmembers[$i][$j])) { 
+                               $text.=","; 
+                       }
                }
                $text.="\n}\n\n";
        }
        
        close(FH);
-       open(FH,"> $file") || die "Probleme d'ouverture du fichier $file";
+       open(FH,"> $file") || die "Can't open file $file";
        print FH "$text";
        close(FH);
        
@@ -272,22 +292,22 @@ sub modiffile_cgi()
 {
        $file=$_[0];
        $text="";
-       open(FH,"$file") || die "Probleme d'ouverture du fichier $file";
+       open(FH,"$file") || die "Can't open file $file";
        while(<FH>)
        {       
                $line=$_;
                #$stdout.="$line";
-               if($line =~ /^authorized_for_system_information=*/i){$text.="authorized_for_system_information=".$userlist1}
-               elsif($line =~ /^authorized_for_configuration_information=*/i){$text.="authorized_for_configuration_information=".$userlist2}
-               elsif($line =~ /^authorized_for_system_commands=*/i){$text.="authorized_for_system_commands=".$userlist3}
-               elsif($line =~ /^authorized_for_all_services=*/i){$text.="authorized_for_all_services=".$userlist4."\n"}
-               elsif($line =~ /^authorized_for_all_hosts=*/i){$text.="authorized_for_all_hosts=".$userlist5}
-               elsif($line =~ /^authorized_for_all_service_commands=*/i){$text.="authorized_for_all_host_commands=".$userlist6."\n"}
-               elsif($line =~ /^authorized_for_all_host_commands=*/i){$text.="authorized_for_all_service_commands=".$userlist7}
+               if($line =~ s/^(authorized_for_system_information=).*$/$1$userlist1/){$text.=$line;}
+               elsif($line =~ s/^(authorized_for_configuration_information=).*$/$1$userlist2/){$text.=$line;}
+               elsif($line =~ s/^(authorized_for_system_commands=).*$/$1$userlist3/){$text.=$line;}
+               elsif($line =~ s/^(authorized_for_all_services=).*$/$1$userlist4/){$text.=$line;}
+               elsif($line =~ s/^(authorized_for_all_hosts=).*$/$1$userlist5/){$text.=$line;}
+               elsif($line =~ s/^(authorized_for_all_service_commands=).*$/$1$userlist6/){$text.=$line;}
+               elsif($line =~ s/^(authorized_for_all_host_commands=).*$/$1$userlist7/){$text.=$line;}
                else {$text.=$line};
        }
        close(FH);
-       open(FH,"> $file") || die "Probleme d'ouverture du fichier $file";
+       open(FH,"> $file") || die "Can't open file $file";
        print FH "$text";
        close(FH);
        
@@ -296,7 +316,7 @@ sub modiffile_cgi()
 sub read_conf()
 {
         my %conf;
-        open (CONFIGFILE, "$_[0]") || die "Unable to open $_[0] for reading !\n";
+        open (CONFIGFILE, "$_[0]") || die "Can't open $_[0] for reading !\n";
         while (<CONFIGFILE>) {
                 chomp($_);
                 ## throw away comments