Escalations (Service / Advanced Services / Hosts)

User / Community contributed content: modifications, patches, extensions, modules, scripts etc.

Escalations (Service / Advanced Services / Hosts)

Postby pebr » Mon Feb 04, 2013 12:11

Hi,

I've been using nconf for a while now and want to share my escalation settings. Since Nconf is missing this i had to define it myself. Stumbled upon a problem this morning when adding escalations for advanced services: When exporting the config the "NConf internal service name" is used instead of the service_name, but I fixed it by editing ExportNagios.pm (I've absolutely no clue using Perl but this works and I'm happy about it :D)

Code: Select all
diff ExportNagios.pm /var/www/nconf/bin/lib/NConf/ExportNagios.pm
1002c1002,1017
<                 }
---
>
>                     # handle advanced service escalations
>                     if($class eq "adv-service-escalation"){
>                         if($attr->[0] eq "service_description"){
>                              my @temporaer = &getItemData($attr->[3]);
>                              foreach my $tempo (@temporaer){
>                                   if($tempo->[0] eq "service_description"){
>                                          &logger(4,"Replacing Advanced Service NConf internal service name");
>                                          &logger(4,"Before: '$attr->[1]' replace with '$tempo->[1]'");
>                                          $attr->[1] = $tempo->[1];
>                                          &logger(4,"After: '$attr->[1]'");
>                                   }
>                              }
>                         }
>                     }
>               }


or for use with patch:

Code: Select all
--- ExportNagios.pm     2011-12-11 02:51:30.000000000 +0100
+++ /var/www/nconf/bin/lib/NConf/ExportNagios.pm        2013-02-04 11:29:06.818636999 +0100
@@ -999,7 +999,22 @@
                         }
                         undef $attr->[1];
                     }
-                }
+
+                    # handle advanced service escalations
+                    if($class eq "adv-service-escalation"){
+                        if($attr->[0] eq "service_description"){
+                             my @temporaer = &getItemData($attr->[3]);
+                             foreach my $tempo (@temporaer){
+                                  if($tempo->[0] eq "service_description"){
+                                         &logger(4,"Replacing Advanced Service NConf internal service name");
+                                         &logger(4,"Before: '$attr->[1]' replace with '$tempo->[1]'");
+                                         $attr->[1] = $tempo->[1];
+                                         &logger(4,"After: '$attr->[1]'");
+                                  }
+                             }
+                        }
+                    }
+               }

                 # apply certain class specific exceptions
                 # caution: this function must always be called before makeValuesDistinct() AND after checking for collector specific items


And adding the Escalations to Nconf is done by issuing these mysql commands (Caution! I've choosen the next free configClasses and configAttrs in a fresh Nconf 1.3.0 Installation)

Code: Select all
INSERT INTO `ConfigClasses` (`id_class`, `config_class`, `friendly_name`, `nav_visible`, `ordering`, `grouping`, `nav_links`, `nav_privs`, `class_type`, `out_file`, `nagios_object`) VALUES
(19, 'service-escalation', 'Service escalation', 'yes', 6, 'Advanced Items', 'Show::overview.php?class=service-escalation;;Add::handle_item.php?item=service-escalation', 'admin', 'collector', 'escalation.cfg', 'serviceescalation'),
(20, 'adv-service-escalation', 'Adv Srv escalation', 'yes', 7, 'Advanced Items', 'Show::overview.php?class=adv-service-escalation;;Add::handle_item.php?item=adv-service-escalation', 'admin', 'collector', 'escalation.cfg', 'serviceescalation'),
(21, 'host-escalation', 'Host escalation', 'yes', 8, 'Advanced Items', 'Show::overview.php?class=host-escalation;;Add::handle_item.php?item=host-escalation', 'admin', 'collector', 'escalation.cfg', 'hostescalation');

INSERT INTO `ConfigAttrs` (`id_attr`, `attr_name`, `friendly_name`, `description`, `datatype`, `max_length`, `poss_values`, `predef_value`, `mandatory`, `ordering`, `visible`, `write_to_conf`, `naming_attr`, `link_as_child`, `link_bidirectional`, `fk_show_class_items`, `fk_id_class`) VALUES
(232, 'name', 'Name', 'Name', 'text', 1024, '', '', 'yes', 1, 'yes', 'no', 'yes', 'no', 'no', NULL, 19),
(234, 'first_notification', 'first notification', '', 'text', 1024, '', '0', 'yes', 2, 'yes', 'yes', 'no', 'no', 'no', NULL, 19),
(235, 'last_notification', 'last notification', '', 'text', 1024, '', '', 'yes', 3, 'yes', 'yes', 'no', 'no', 'no', NULL, 19),
(236, 'notification_interval', 'notification interval', '', 'text', 1024, '', '', 'yes', 4, 'yes', 'yes', 'no', 'no', 'no', NULL, 19),
(237, 'service_description', 'service description', '', 'assign_many', 0, '', '', 'yes', 6, 'yes', 'yes', 'no', 'no', 'no', 3, 19),
(238, 'contact_groups', 'contact groups', '', 'assign_many', 0, '', '', 'yes', 7, 'yes', 'yes', 'no', 'no', 'no', 6, 19),
(239, 'host_name', 'host name', '', 'assign_many', 0, '', '', 'yes', 5, 'yes', 'yes', 'no', 'no', 'no', 1, 19),
(254, 'escalation_period', 'escalation period', '', 'assign_one', 0, '', '', 'no', 8, 'yes', 'yes', 'no', 'no', 'no', 7, 19),
(240, 'name', 'Name', 'Name', 'text', 1024, '', '', 'yes', 1, 'yes', 'no', 'yes', 'no', 'no', NULL, 20),
(241, 'first_notification', 'first notification', '', 'text', 1024, '', '0', 'yes', 2, 'yes', 'yes', 'no', 'no', 'no', NULL, 20),
(242, 'last_notification', 'last notification', '', 'text', 1024, '', '', 'yes', 3, 'yes', 'yes', 'no', 'no', 'no', NULL, 20),
(243, 'notification_interval', 'notification interval', '', 'text', 1024, '', '', 'yes', 4, 'yes', 'yes', 'no', 'no', 'no', NULL, 20),
(244, 'service_description', 'service description', '', 'assign_many', 0, '', '', 'yes', 6, 'yes', 'yes', 'no', 'no', 'no', 18, 20),
(245, 'contact_groups', 'contact groups', '', 'assign_many', 0, '', '', 'yes', 7, 'yes', 'yes', 'no', 'no', 'no', 6, 20),
(246, 'host_name', 'host name', '', 'assign_many', 0, '', '', 'yes', 5, 'yes', 'yes', 'no', 'no', 'no', 1, 20),
(255, 'escalation_period', 'escalation period', '', 'assign_one', 0, '', '', 'no', 8, 'yes', 'yes', 'no', 'no', 'no', 7, 20),
(256, 'escalation_period', 'escalation period', '', 'assign_one', 0, '', '', 'no', 8, 'yes', 'yes', 'no', 'no', 'no', 7, 21),
(247, 'name', 'Name', 'Name', 'text', 1024, '', '', 'yes', 1, 'yes', 'no', 'yes', 'no', 'no', NULL, 21),
(248, 'first_notification', 'first notification', '', 'text', 1024, '', '0', 'yes', 2, 'yes', 'yes', 'no', 'no', 'no', NULL, 21),
(249, 'last_notification', 'last notification', '', 'text', 1024, '', '', 'yes', 3, 'yes', 'yes', 'no', 'no', 'no', NULL, 21),
(250, 'notification_interval', 'notification interval', '', 'text', 1024, '', '', 'yes', 4, 'yes', 'yes', 'no', 'no', 'no', NULL, 21),
(251, 'host', 'host', '', 'assign_many', 0, '', '', 'yes', 6, 'yes', 'yes', 'no', 'no', 'no', 1, 21),
(252, 'contact_groups', 'contact groups', '', 'assign_many', 0, '', '', 'yes', 7, 'yes', 'yes', 'no', 'no', 'no', 6, 21),
(254, 'escalation_period', 'escalation period', '', 'assign_one', 0, '', '', 'no', 8, 'yes', 'yes', 'no', 'no', 'no', 7, 19),
(255, 'escalation_period', 'escalation period', '', 'assign_one', 0, '', '', 'no', 8, 'yes', 'yes', 'no', 'no', 'no', 7, 20),
(256, 'escalation_period', 'escalation period', '', 'assign_one', 0, '', '', 'no', 8, 'yes', 'yes', 'no', 'no', 'no', 7, 21);


But you have to be carefull when adding service and advanced-service escalations: You can choose Hosts and services/advanced-services - wether they exist on the host or not! If you choose a service/advanced-service that doesn't exist on a host generating your nagios config will fail. Since I only use 5-6 escalations it doesn't bother me, but maybe someone (or even me when I have more sparetime) will fix this in the Export.

Bye
Peter
Last edited by pebr on Tue Apr 09, 2013 08:03, edited 1 time in total.
pebr
beginner
beginner
 
Posts: 9
Joined: Mon Feb 04, 2013 09:54

Re: Escalations (Service / Advanced Services / Hosts)

Postby Guest » Wed Apr 03, 2013 18:02

How would this work for host escalations? The php code is just for service escalations.
Guest
 

Re: Escalations (Service / Advanced Services / Hosts)

Postby pebr » Thu Apr 04, 2013 07:25

As you can see in the first INSERT INTO it also creates Host Escalations. The Diff is for "Advanced Services" - without the Code the "Nconf friendly Name" ist put into nagios.conf which won't work...
pebr
beginner
beginner
 
Posts: 9
Joined: Mon Feb 04, 2013 09:54

Re: Escalations (Service / Advanced Services / Hosts)

Postby guest » Thu Apr 04, 2013 17:57

I think I have the database side of things setup correctly. The image here shows the Nconf attributes for the hostescalation class. Does it look correct? Would a dump of this part of the database be better to look at?

When I try to setup a host escalation and generate the nagios config I get an error, which makes me think it's that php code for ExportNagios.pm.
(Also, sorry I'm only logged in as a guest...I haven't been granted approval for my username I requested yet.)

Website: http://www.nagios.org
Reading configuration data...
Read main config file okay...
Processing object config file '/sites/nconf/temp/global/escalations.cfg'...
Processing object config file '/sites/nconf/temp/global/timeperiods.cfg'...
Processing object config file '/sites/nconf/temp/global/contacts.cfg'...
Processing object config file '/sites/nconf/temp/global/misccommands.cfg'...
Processing object config file '/sites/nconf/temp/global/checkcommands.cfg'...
Processing object config file '/sites/nconf/temp/global/host_templates.cfg'...
Processing object config file '/sites/nconf/temp/global/service_templates.cfg'...
Processing object config file '/sites/nconf/temp/global/contactgroups.cfg'...
Processing object config file '/sites/nconf/temp/Default_collector/service_dependencies.cfg'...
Processing object config file '/sites/nconf/temp/Default_collector/host_dependencies.cfg'...
Processing object config file '/sites/nconf/temp/Default_collector/advanced_services.cfg'...
Processing object config file '/sites/nconf/temp/Default_collector/services.cfg'...
Processing object config file '/sites/nconf/temp/Default_collector/servicegroups.cfg'...
Processing object config file '/sites/nconf/temp/Default_collector/hosts.cfg'...
Error: Invalid host object directive 'hostescalation'.
Error: Could not add object property in file '/sites/nconf/temp/Default_collector/hosts.cfg' on line 1685.

Error processing object config files!

Image
guest
 

Re: Escalations (Service / Advanced Services / Hosts)

Postby pebr » Fri Apr 05, 2013 07:59

You didn't use the INSERT INTO statements from me, right?

My host-escalation (note the different writing) looks like this:

Image

I don't think it's the php code since host-escalation don't need any change. The php change is only for advanced-service escalations. It's a faulty Setting for your attribute

Edit:
Change "write attribute to configuration?" to "No" for your PK "hostescalation"
pebr
beginner
beginner
 
Posts: 9
Joined: Mon Feb 04, 2013 09:54

Re: Escalations (Service / Advanced Services / Hosts)

Postby Lijiman » Fri Apr 05, 2013 11:06

No, I didn't use your INSERT statements, as my nconf is far from a fresh install. :)

I still can't get it working, but I noticed there were few things in the class definition that were different.
I had it trying to write to escalations.cfg so I changed to escalation.cfg, also I had it class type admin so I changed to collector, and I changed everything else in there to match yours.

Code: Select all
(19, 'host-escalation', 'Host escalation', 'yes' , 4 , 'AdvancedItems' , 'Show::overview.php?class=host-escalation;;Add::handle_item.php?item=host-escalation' , 'admin' , 'collector' , 'escalation.cfg' , 'hostescalation');


I always have had the PK for the attributes as not writing to the config. I had found some other post on the webz about that previously.

Code: Select all
232 , name , Host escalation name ,  , text , 1024 ,  ,  , yes , 1 , yes , no , yes , no , no , NULL , 19
233 , host_name , Hostname ,  , assign_many , 0 ,  ,  , yes , 7 , yes , yes , no , no , yes , 1 , 19
236 , contact_groups , Contact groups ,  , assign_many , 0 ,  ,  , yes , 8 , yes , yes , no , no , yes , 6 , 19
237 , first_notification , First notification ,  , text , 1024 ,  ,  , yes , 2 , yes , yes , no , no , no , NULL , 19
238 , last_notification , Last notification ,  , text , 1024 ,  ,  , yes , 5 , yes , yes , no , no , no , NULL , 19
239 , notification_interval , Notification interval ,  , text , 1024 ,  ,  , yes , 6 , yes , yes , no , no , no , NULL , 19
240 , escalation_period , Escalation period ,  , assign_one , 0 ,  ,  , no , 9 , yes , yes , no , no , no , 7 , 19
242 , hostescalation , Host escalation plan ,  , assign_one , 0 ,  ,  , no , 29 , yes , yes , no , no , no , 19 , 1
Lijiman
beginner
beginner
 
Posts: 6
Joined: Wed Apr 03, 2013 17:59

Re: Escalations (Service / Advanced Services / Hosts)

Postby pebr » Fri Apr 05, 2013 11:54

You could use my Insert Statements if you change the IDs (matching in ConfigClasses and ConfigAttributes) to the next free values. In fact you could also do it by hand, the settings I posted here are working on 6 Sites now without any trouble. You have a lot more ConfigAttributes than I have - maybe some of them are configured wrong
pebr
beginner
beginner
 
Posts: 9
Joined: Mon Feb 04, 2013 09:54

Re: Escalations (Service / Advanced Services / Hosts)

Postby Lijiman » Fri Apr 05, 2013 20:53

I think I just realized why it's not working.

Right now I have it setup using both INSERT statements you provided (with a few minor modifications). What I was doing before was I had added the hostescalation attribute to the host class, which is why it fails to generate the config. The Nagios documentation says that the host object definition doesn't have hostescalation in it.

How do you assign the hostescalation plan to a host or hostgroup through the nconf gui? I think that's what has been tripping me up all along!

Code: Select all
Error: Invalid host object directive 'hostescalation'.
Error: Could not add object property in file '/sites/nconf/temp/Default_collector/hosts.cfg' on line 1685.
Lijiman
beginner
beginner
 
Posts: 6
Joined: Wed Apr 03, 2013 17:59

Re: Escalations (Service / Advanced Services / Hosts)

Postby Lijiman » Fri Apr 05, 2013 21:58

D'oh, nevermind! You assign it from host escalation, not from the host itself. So now I'm waiting for my testing to confirm host escalations...then to tackle service escalations with the php code. :D :D :D
Lijiman
beginner
beginner
 
Posts: 6
Joined: Wed Apr 03, 2013 17:59

Re: Escalations (Service / Advanced Services / Hosts)

Postby Lijiman » Fri Apr 05, 2013 22:29

Woohoo! Hostescalations are working now. Thank you very much for your help btw. :)

I'm not able to get the php code working now. :( I haven't changed anything from the INSERT statements, so my adv services should be identical to yours

When I generate the config I get this...

Reading configuration data...
Error: Cannot open main configuration file '/sites/nconf/temp/test/Default_collector.cfg' for reading!
Error processing main config file!

Here is some code before and after the code I input from your original post. I removed the final } bracket...seemed like there was one extra...is that right?

Code: Select all
if(defined($id_item->[1]) || ($monitor_path && $path =~ /\Q$monitor_path\E/)){

                # look for linked items, that are server-specific (hosts, services, hostgroups, servicegroups),
                # check if they exist on the current Nagios server, remove them if not;

                # this routine makes sense both for collectors and monitors, since hosts/services can also be disabled (not monitored) on a monitor,
                # and must therefore be removed from any items they might be linked to;

                foreach my $attr (@item_links){

                    # in "collector" context, $id_item->[1] contains the collector's ID
                    # in "monitor"   context, $id_item->[1] is undefined
                    unless(&checkItemExistsOnServer($attr->[3],$id_item->[1]) eq "true"){

                        # if the linked item doesn't exist on current server, empty the linking attribute
                        # (careful, there may be multiple instances of the same linking attribute per item)
                        # the empty linking attributes will be processed later (after class_dependent_processing() & makeValuesDistinct() )
                        if($id_item->[1]){
                            &logger(4,"Removing item '$attr->[3]' from $class '$id_item->[0]' because the item doesn't exist on collector '$id_item->[1]'");
                        }else{
                            &logger(4,"Removing item '$attr->[3]' from $class '$id_item->[0]' because the item is not monitored");
                        }
                        undef $attr->[1];
                    }
                }

                # handle advanced service escalations
                     if($class eq "adv-service-escalation"){
                         if($attr->[0] eq "service_description"){
                              my @temporaer = &getItemData($attr->[3]);
                              foreach my $tempo (@temporaer){
                                   if($tempo->[0] eq "service_description"){
                                          &logger(4,"Replacing Advanced Service NConf internal service name");
                                          &logger(4,"Before: '$attr->[1]' replace with '$tempo->[1]'");
                                          $attr->[1] = $tempo->[1];
                                          &logger(4,"After: '$attr->[1]'");
                                   }
                              }
                         }
                     }

                # apply certain class specific exceptions
                # caution: this function must always be called before makeValuesDistinct() AND after checking for collector specific items
                @item_links = &class_dependent_processing($class, @item_links);

                # consolidate multi-line attributes into one line
                @item_links = &makeValuesDistinct(@item_links);
Lijiman
beginner
beginner
 
Posts: 6
Joined: Wed Apr 03, 2013 17:59

Re: Escalations (Service / Advanced Services / Hosts)

Postby pebr » Mon Apr 08, 2013 08:08

No, the Bracket shouldn't be an extra - this is a diff from a working installation so it should be needed - and the php code is only for advanced-services! If you stick with "normal" services for escalation only (for testing) the php code doesn't matter. Let's stick with a single service escalation (no advanced-services) for the beginning. The Default-Collector failure is not necessary an escalation Problem.
pebr
beginner
beginner
 
Posts: 9
Joined: Mon Feb 04, 2013 09:54

Re: Escalations (Service / Advanced Services / Hosts)

Postby Lijiman » Mon Apr 08, 2013 16:16

Ok, I have tried with and without the bracket and got that failure...sorry should have mentioned it earlier. I'm using only advanced services on several nagios installations, so I'll have to go the php code fix route. I'll work on it today again.

EDIT: I only get the Default-Collector failure when adding that code block to ExportNagios.pm. If I remove the code it will generate the config successfully.
Lijiman
beginner
beginner
 
Posts: 6
Joined: Wed Apr 03, 2013 17:59

Re: Escalations (Service / Advanced Services / Hosts)

Postby pebr » Tue Apr 09, 2013 07:49

I can't understand that - but if you use different "advanced service name" than "service description" for an advanced-service the generated config should throw an error - and for this case the php workaround is needed

Edit:
Did you apply the diff by hand? Or did you use patch?
Nevermind - i didn't ever post the patch version until now...

Edit2:
You could enable debug - then the modified file will print some debug lines when it's replacing certain advanced-service-names
pebr
beginner
beginner
 
Posts: 9
Joined: Mon Feb 04, 2013 09:54

Re: Escalations (Service / Advanced Services / Hosts)

Postby Lijiman » Tue Apr 09, 2013 20:11

Wow, I'm just dumb. I didn't remove the } before the code block, which is why I thought the very last closing } was an extra one.

pebr, thank you very very much for your help on this!!! :D :D
Lijiman
beginner
beginner
 
Posts: 6
Joined: Wed Apr 03, 2013 17:59

Re: Escalations (Service / Advanced Services / Hosts)

Postby pebr » Wed Apr 10, 2013 07:58

Glad to hear everything is working now! :)
pebr
beginner
beginner
 
Posts: 9
Joined: Mon Feb 04, 2013 09:54

Next

Return to Contributions

Who is online

Users browsing this forum: No registered users and 2 guests

cron