On 07/28/2015 12:04 PM, Thorsten Garrels wrote:

> ***********************
>
> Hi @ all,
>
> I'm new to Icinga2 (and somewhat to monitoring in general).
> I've already consulted http://docs.icinga.org/icinga2 and while the
> documentation appears to be comprehensive, it is also very dense and
> -- at least to me -- there is some sort of howto-like-glue missing,
> to form the picture of all the bits an pieces :-)
>
>
> What I'm trying to do for starters is to monitor some Cisco switches,
> for instance port status.
>
> I downloaded https://labs.consol.de/nagios/check_nwc_health/ and I'm using
> this as check_command.
>
> My idea now was to generate templates for the various Cisco Switch models,
> e.g. the 2940 in my lab:
>
>

No reply because this is incredible simple?  ;-)


I pulled my hair because nothing seemed to work. And all over sudden is
does now. Here's an apparently working config (just the changed parts)


- modified my lab switch stanza as follows:

===========================================================================
object Host "lab_switch"{
     import "generic-host"
     import "cisco-2940"
     vars.devicetype = "switch"
     vars.devicemanufacturer = "cisco"
     vars.deviceproduct = "2940"
     address = "172.30.100.36"


    vars.monitorInterfaces = [ "FastEthernet0/1",
                               "FastEthernet0/2",.
                               "FastEthernet0/3",.
                               "FastEthernet0/6",.
                               "FastEthernet0/7",.
                               "GigabitEthernet0/1" ]


}

===========================================================================

- modified the apply Service file as follows:

===========================================================================
* loop over the host.vars.interfaces dictionary
  * for (key => value in dict) means `interface_name` as key
  * and `interface_config` as value. Access config attributes
  * with the indexer (`.`) character.
  */
apply Service "if-" for (interface_name => interface_config in
host.vars.interfaces) {
   import "generic-service"
   check_command = "check_nwc_health_2c"
   display_name = "IF-" + interface_name

  /* use the key as interface argument (no duplication of values in
host.vars.interfaces) */
   vars.check_nwc_health_name = interface_name


[...]

     check_interval = 10
     retry_interval = 10


assign where interface_name in host.vars.monitorInterfaces

}

===========================================================================


Yesterday, checkconfig went fine, as did restart. But it just did not
recognize "interface_name" in the assign statement(i.e. it as assigned
everywhere). If I hardcoded "FastEthernet0/1" instead of
"interface_name" it worked well, for _every_ interface in the loop, if I
hardcoded "FastEthernet0/4" it did not do anything in the loop. So the
statement itself was working.


I tried


assign where vars.check_nwc_health_name in host.vars.monitorInterfaces



but checkconfig complained:

---------------------------------------------------------------------
critical/config: Error: Error while evaluating expression: Tried to
access undefined script variable 'vars'
Location:
/etc/icinga2/conf.d/test/commands/commandConditioner.conf(65): /*
assign where interface_name in host.vars.monitorInterfaces */
---------------------------------------------------------------------

I tried



    var ifName = interface_name
    assign where ifName in host.vars.monitorInterfaces



in response to this article: https://dev.icinga.org/issues/7610

but checkconfig complained:

---------------------------------------------------------------------
critical/config: Error: Error while evaluating expression: Tried to
access undefined script variable 'ifName'
Location:
/etc/icinga2/conf.d/test/commands/commandConditioner.conf(66):
/etc/icinga2/conf.d/test/commands/commandConditioner.conf(67):     var
ifName = interface_name
/etc/icinga2/conf.d/test/commands/commandConditioner.conf(68):
assign where ifName in host.vars.monitorInterfaces

         ^^^^^^
/etc/icinga2/
---------------------------------------------------------------------



Anyway, I'm happy it works now and hope this will be of help to others!


cheers,

Thorsten









_______________________________________________
icinga-users mailing list
[email protected]
https://lists.icinga.org/mailman/listinfo/icinga-users

Reply via email to