Ad Widget

Collapse

PATCH: ItemID Macro

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • James Wells
    Senior Member
    • Jun 2005
    • 664

    #1

    PATCH: ItemID Macro

    Greetings,

    Here is a simple patch to add the ItemID as a macro for notifications. I recently worked on a project where I needed to manufacture URL's to get to the latest data graph any time a certain set of alerts came in. Rather than script the URL creation outside of the Zabbix server, I wrote this patch to provide a new macro: {ITEM.ID}.

    Please note that this macro will only return the ItemID of one item, so if you are using a complex trigger, this will not give you the second, third, etc ItemIDs.
    Attached Files
    Unofficial Zabbix Developer
  • richlv
    Senior Member
    Zabbix Certified Trainer
    Zabbix Certified SpecialistZabbix Certified Professional
    • Oct 2005
    • 3112

    #2
    mm. might be neat to polish it to provide additional functionality as other macros do for more advanced triggers ({ITEM.ID1}, {ITEM.ID2} etc).

    and frontend support (in network maps and maybe elsewhere) would also be interesting... then the patch could be submitted on the issue tracker
    Zabbix 3.0 Network Monitoring book

    Comment

    • James Wells
      Senior Member
      • Jun 2005
      • 664

      #3
      Originally posted by richlv
      mm. might be neat to polish it to provide additional functionality as other macros do for more advanced triggers ({ITEM.ID1}, {ITEM.ID2} etc).
      I think I can manage that. Prolly have it submitted over the weekend.
      Unofficial Zabbix Developer

      Comment

      • fjrial
        Senior Member
        • Feb 2010
        • 140

        #4
        I'm trying to use your patch and I have to say sorry, because my knowledge in C code and so on pointers has been degraded to its minimum..

        I'm trying to get the itemid for a trigger ID.. this's the call to your function
        Code:
        get_itemid_status = DBget_item_id_by_triggerid(event->objectid, itemid, 0);
        event->objectid has the triggerID..
        But when this peace of code gets executed, zabbix_server crashes, obviously by a bad usage with that pointer..

        By the definition of your function, itemid should be a pointer to a pointer??
        is that right??

        I mean, itemid could be a simple zbx_uint64_t.. or am I not understanding this??

        Thanks for any help.

        Comment

        • fjrial
          Senior Member
          • Feb 2010
          • 140

          #5
          I forgot to mention that I'm trying to use your function in src/zabbix_server/actions.c.. not in expression.c

          I want to check for an action with a KNOWN name, search trigger ID for the event and check which host caused the trigger to fire. Depending on this, I'll let the action continue, or I'll change event->skip_actions = 1 in order to skip this...

          Edited:
          Code:
                          if (SUCCEED == check_action_conditions(event, &action))
                          {
                                  zabbix_log(LOG_LEVEL_DEBUG, "Conditions match our event. Execute operations.");
          
                                  MYSQL *connection, mysql;
                                  MYSQL_RES *result;
                                  MYSQL_ROW row;
                                  int query_state;
                                  int get_itemid_status;
                                  char *itemid = NULL;
                                  char query_rt [120];
          
                                  result = DBselect("select name from actions where actionid=%s",row[0]);
          
                                  if (NULL != (row = DBfetch(result)))
                                  {
                                          if (row[0] == "TICKET RT")
                                          {
                                                  get_itemid_status = DBget_item_id_by_triggerid(event->objectid, &itemid, 1);
                                                  if (get_itemid_status == SUCCEED)
                                                  {
                                                          result = DBselect("select host from hosts inner join items on hosts.hostid=items.hostid where itemid=%s",*itemid);
                                                                  if (NULL != (row = DBfetch(result)))
                                                                  {
                                                                          mysql_init(&mysql);
                                                                          //connect to request tracker
                                                                          connection = mysql_real_connect(&mysql,"host","user","pass","rt3",0,NULL,0);
                                                                          if (connection != NULL)
                                                                          {
                                                                                  zbx_snprintf(query_rt, sizeof(query_rt), "select id from Tickets where queue=6 and Subject like '%s Equipo caido' and (Status='new' or Status='open')", row[0]);
                                                                                  query_state = mysql_query(connection, query_rt);
                                                                                  if (query_state == 0)
                                                                                  {
                                                                                          result = mysql_store_result(connection);
                                                                                          if (mysql_num_rows(result)>0)
                                                                                                  event->skip_actions = 1;
                                                                                  }
                                                                          }
                                                                  }
                                                  }
                                          }
                                  }
          
                                  if (!event->skip_actions)
                                  {
                                  DBstart_escalation(action.actionid, event->source == EVENT_SOURCE_TRIGGERS ? event->objectid : 0, event->eventid);
          
                                  if (event->source == EVENT_SOURCE_DISCOVERY || event->source == EVENT_SOURCE_AUTO_REGISTRATION)
                                          execute_operations(event, &action);
          
                                  DBfree_result(result);
                                  }
                          }
          Last edited by fjrial; 07-09-2010, 10:53. Reason: add code

          Comment

          • James Wells
            Senior Member
            • Jun 2005
            • 664

            #6
            Originally posted by fjrial
            I'm trying to get the itemid for a trigger ID.. this's the call to your function
            Code:
            get_itemid_status = DBget_item_id_by_triggerid(event->objectid, itemid, 0);
            IIRC, itemid would needs to be &itemid as it is an indirect pointer to the value. Unfortunately, pointers are my absolute weakest area programming.

            Originally posted by fjrial
            Code:
                                    int get_itemid_status;
                                    char *itemid = NULL;
            Not sure, but I suspect the itemid here is the culprit. Looking at the actual function declaration, I see that the itemid is indeed an indirect pointer, but you are declaring it here as a direct pointer. Try changing it to;
            Code:
                                    int get_itemid_status;
                                    char **itemid;
            EDIT: BTW, I didn't get a chance to work on this over the weekend afterall. Hopefully this evening.
            Unofficial Zabbix Developer

            Comment

            • fjrial
              Senior Member
              • Feb 2010
              • 140

              #7
              Sorry, I put the wrong code, I realized about those mistakes, but the most important mistake was a string comparison like this...
              if (row[0] == "TEXT") instead of using strcmp

              Sorry, I need to stay apart of PHP programming for a while

              Thanks again for your help.

              Comment

              • fjrial
                Senior Member
                • Feb 2010
                • 140

                #8
                James.. I used your function in a patch that I've submitted in another thread on forums.. sorry for didn't ask you before.. I didn't touch your comments over the function DBget_item_id_by_triggerid..

                Hope that you don't mind..
                Last edited by fjrial; 09-09-2010, 09:55. Reason: correct mistakes

                Comment

                Working...