sni / Thruk

Thruk is a multibackend monitoring webinterface for Naemon, Nagios, Icinga and Shinken using the Livestatus API.
http://www.thruk.org
Other
408 stars 148 forks source link

Macros, custom vars and icinga2 #524

Closed TomGudman closed 9 years ago

TomGudman commented 9 years ago

Hi,

Issue

As discussed in IRC, my problem is I cannot find how to access my custom variables in the action menu using macros. The theory is a macro $_HOSTOS$ gives you access to the host's custom variable called 'os'. However I cannot make it work.

Context

object Host "blahblah" {
  import "generic-host"
  address = "10.200.19.18"
  display_name = "10.200.19.18; fake display name - prout"
  vars.os = "Cisco"
  vars.icrm = "a0LFlbQAAT"
  action_url = "http://www.google.com.au"
  notes_url  = "a0LFlbQAAT"
  notes = "Thomas"
}

Thruk config

Note: I am aware that I should not use thruk.conf directly but I am just building a PoC so it does not matter yet.

-- thruk.conf
show_custom_vars = *
[..]
enable_icinga_features = 1
[..]
<action_menu_items>
    hostmenu = {\
       "icon": "/thruk/themes/{{theme}}/images/dropdown.png",\
       "title": "Host Menu",\
       "menu": [\
           {\
               "icon": "/thruk/themes/{{theme}}/images/page_white_text.png",\
               "label": "CRM service page",\
               "action": "http://foobar/services/$_HOSTOS$",\
               "target": "_blank"\
           },\
           "-",\
       ]\
    }
</action_menu_items>
<action_menu_apply>
    hostmenu    = .*;$             # matches all hosts only
    #servicemenu = .*;.+$           # matches all services on all hosts
    #specialmenu = ^Host;Service$   # matches an exact service on one host only
    #cpu_menu    = .*;^CPU          # matches all services starting with 'CPU'
    #hostmenu    = ^Host            # matches all hosts starting with 'Host'
    #demomenu    = ^Demo;           # matches all services on the 'Demo' host
    #demomenu    = ^Test;           # a menu name can be used multiple times
</action_menu_apply>

--  thruk_local.conf
<Component Thruk::Backend>
    <peer>
        name    = icinga
        id      = 7215e
        type    = livestatus
        <options>
            peer          = /var/run/icinga2/cmd/livestatus
        </options>
    </peer>
</Component>

Result

thruk-macro-issue

sni commented 9 years ago

I'd say $_HOSTOS$ is correct. Have you tried clicking on the link? Because the macros will be replaced right after clicking the link, not before that event because some Macros change over time.

TomGudman commented 9 years ago

Hi Sni,

:+1:

Good news, with $_HOSTos$ it works so the case has to be respected.

I did not expect the macros to be interpolated on click but to be interpolated on page generation aka the host page containing the menu. I always saw the macro name and not the value in the URL and I wrongly assumed that it would not work and NEVER clicked on the link!