Ad Widget

Collapse

Try to add variable "{ITEM.NAME} in alert message

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • just2blue4u
    Senior Member
    • Apr 2006
    • 347

    #1

    Try to add variable "{ITEM.NAME} in alert message

    Hi there!

    am trying to add the variable {ITEM.NAME} into my alert messages. Therefore i modified the file "src/zabbix_server/expression.c".
    This is the first time i modify c source code, so perhaps it looks very strange to experts/professionals.

    This is untested code for zabbix_server v1.1.3.
    If someone interested wants to have a look (or perhaps add/modify something), here we go:
    Code:
    [root@intra2dmz-1 zabbix_server]# diff expression.c expression.c.orig
    20,23d19
    < /*hw*/
    < // Code within this Tags modified or added by Heiner Wulfhorst ([email protected])
    < /**/
    <
    579,581d574
    < /*hw*/
    < #define MVAR_ITEM_NAME                        "{ITEM.NAME}"
    < /**/
    773,777d765
    < /*hw*/
    <               else if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY) &&
    <                       strncmp(pr, MVAR_ITEM_NAME, strlen(MVAR_ITEM_NAME)) == 0)
    <               {
    <                       var_len = strlen(MVAR_ITEM_NAME);
    779,803d766
    < //                    snprintf(sql,sizeof(sql)-1,"select distinct i.key_ from triggers t, functions f,items i, hosts h"
    < //                            " where t.triggerid=%d and f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid"
    < //                            " order by i.key_", trigger->triggerid);
    <                       snprintf(sql,sizeof(sql)-1,"select distinct i.description from triggers t, functions f,items i, hosts h"
    <                               " where t.triggerid=%d and f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid"
    <                               " order by i.description", trigger->triggerid);
    <
    <                       result = DBselect(sql);
    <                       row=DBfetch(result);
    <
    <                       if(!row || DBis_null(row[0])==SUCCEED)
    <                       {
    <                               zabbix_log( LOG_LEVEL_ERR, "No MVAR_ITEM_NAME in substitute_simple_macros. Triggerid [%d]", trigger->triggerid);
    <                               zabbix_syslog("No TRIGGER.KEY in substitute_simple_macros. Triggerid [%d]", trigger->triggerid);
    <                               /* remove variable */
    <                               *replace_to = '\0';
    <                       }
    <                       else
    <                       {
    <                               snprintf(replace_to, sizeof(replace_to), "%s", row[0]);
    <                       }
    <
    <                       DBfree_result(result);
    <               }
    < /**/
    [root@intra2dmz-1 zabbix_server]#
    Feedback welcome!

    Tomorrow i'll continue here...
    Big ZABBIX is watching you!
    (... and my 48 hosts, 4513 items, 1280 triggers via zabbix v1.6 on CentOS 5.0)
Working...