Ad Widget

Collapse

How to add HOSTGROUP macro to an action

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • angelhc
    Senior Member
    Zabbix Certified Specialist
    • Nov 2009
    • 226

    #1

    How to add HOSTGROUP macro to an action

    Hi all,

    We're implementing a connector between the zabbix events to our Ticketing system (jira), all are running so good but for the correct classification of each event we need to add the Hostgroup to the Action and no way we found.
    We try to do those things:
    1.- Add a new template macro called {$Hostgroup} and using it on all the servers.
    2.- Add like a field into the Default message field the {$Hostgroup}, it doesnt runs.
    3.- Add the macro inside each host like host macro and use it on the Default message field, {$Hostgroup}, it doesnt runs.

    4.- Change the Default message to a remote command like this:
    hostname:/home/zabbix/scripts/send_mail.sh {$HOSTGROUP} "{HOSTNAME}" "{TRIGGER.NAME}" "{TRIGGER.COMMENT}"

    The send_mail.sh is :
    echo $1 $2 $3 $4 | /bin/mail -s "test" [email protected]

    But the messages doesnt have the {$Hostgroup} fill, they appears like {}.


    For a correct implementation we need to have the hostgroup corresponding to each server because as we develop it each event comes to a different support group queue.
    Any idea?
    Maybe a develop inside the actions.inc.php?

    Each server only have one hostgroup deffined.

    Thanks so much!
    Number of hosts 1600,Number of items +90k,Number of triggers +22k, Number of users +100, New values per second +1270

    http://zabbixes.wordpress.com/
  • untergeek
    Senior Member
    Zabbix Certified Specialist
    • Jun 2009
    • 512

    #2
    We had to do a curious bit of php scripting to get a link to "latest data" or "graph" into our notifications/actions. It involved passing the trigger or eventid to a "new" php script we added to the action. This is great when all you want is to have a clickable link, but it won't work for what you're doing as the item is needed as part of the process.

    I would suggest writing a shell script of some flavor that can connect to the zabbix db -- or better yet python or ruby which use the Zabbix API -- and reverse engineer the group name from a trigger or eventid, which can be passed by an action. This can be especially troublesome if you, like us, have hosts residing in multiple groups. Do you select just one? All of them? How do you choose?

    Comment

    • angelhc
      Senior Member
      Zabbix Certified Specialist
      • Nov 2009
      • 226

      #3
      Hi!
      Thanks for your answer untergeek
      Just now our servers are on more than one hostgroup because the user rights organization but this issue is so necessary and we can dispense of it and assign only one hostgroup for each server.

      Please, can you post any example about your php scripting modification?

      Thanks a lot!

      Regards.
      Number of hosts 1600,Number of items +90k,Number of triggers +22k, Number of users +100, New values per second +1270

      http://zabbixes.wordpress.com/

      Comment

      • untergeek
        Senior Member
        Zabbix Certified Specialist
        • Jun 2009
        • 512

        #4
        PHP Code:
        $hostgroupsql DBselect('select name,groupid from groups where groupid in (select groupid from hosts_groups where hostid='.$YOURHOSTIDHERE.')');
        $hostgroupidsbyname = array();
        while(
        $tmpresult DBfetch($hostgroupsql)){
          
        $hostgroupidsbyname[$tmpresult['name']] = $tmpresult['groupid'];
          if(
        $tmpresult['name'] == 'Network Hardware'){
            
        $netgroupidsql "select usrgrpid from usrgrp where NAME LIKE 'Network %dministrators'";
            
        $netgroupres DBfetch(DBselect($netgroupidsql));
            
        $groupidlist $groupidlist ',' $netgroupres['usrgrpid'];
          }
          if(
        $tmpresult['name'] == 'Hosted Hardware'){
            
        $unixgroupidsql "select usrgrpid from usrgrp where NAME LIKE 'UNIX %dministrators'";
            
        $unixgroupres DBfetch(DBselect($unixgroupidsql));
            
        $groupidlist $groupidlist ',' $unixgroupres['usrgrpid'];
          }

        Comment

        • angelhc
          Senior Member
          Zabbix Certified Specialist
          • Nov 2009
          • 226

          #5
          Wow... tomorrow at work I've to read it with care cause at home is so difficult to understant it (for me).


          In the other hand, as I can see you are working at trigger level but... we have more than 6K triggers. It's necessary to modify each one? It's no way to work with the action ones?

          Thanks again.
          Number of hosts 1600,Number of items +90k,Number of triggers +22k, Number of users +100, New values per second +1270

          http://zabbixes.wordpress.com/

          Comment

          • untergeek
            Senior Member
            Zabbix Certified Specialist
            • Jun 2009
            • 512

            #6
            The code I pasted is from code I wrote we use to send acknowledgement notification to each user associated with a given usergroup (which is in turn associated with a given server group). It is used in the front-end.

            You shouldn't have to edit your triggers or templates. The idea would be to pass a triggerid or eventid to an external script, then use the API or direct DB access to extract the needed data (group name in your case) based on what is found.

            Comment

            Working...