--- hobbitd/do_alert.c 2008/01/11 13:11:07 1.101 +++ hobbitd/do_alert.c 2008/01/14 20:58:34 @@ -50,6 +50,32 @@ int include_configid = 0; /* Whether to include the configuration file linenumber in alerts */ int testonly = 0; /* Test mode, dont actually send out alerts */ +/* + * This generates a unique ID for an event. + * The ID is an MD5 hash of the hostname, testname and the + * event start-time. + */ +static char *make_alertid(char *hostname, char *testname, time_t eventstart) +{ + static char result[33]; + unsigned char id[16]; + char *key; + void *md5handle; + int i, j; + + key = (char *)malloc(strlen(hostname)+strlen(testname)+15); + sprintf(key, "%s|%s|%d", hostname, testname, (int)eventstart); + + md5handle = (void *)malloc(myMD5_Size()); + myMD5_Init(md5handle); + myMD5_Update(md5handle, key, strlen(key)); + myMD5_Final(id, md5handle); + + for (i=0, j=0; (i < 16); i++, j+=2) sprintf(result+j, "%02x", id[i]); + result[32] = '\0'; + return result; +} + static int servicecode(char *testname) { /* @@ -426,6 +452,7 @@ char *p; int ip1=0, ip2=0, ip3=0, ip4=0; char *bbalphamsg, *ackcode, *rcpt, *bbhostname, *bbhostsvc, *bbhostsvccommas, *bbnumeric, *machip, *bbsvcname, *bbsvcnum, *bbcolorlevel, *recovered, *downsecs, *eventtstamp, *downsecsmsg, *cfidtxt; + char *alertid, *alertidenv; int msglen; cfidtxt = (char *)malloc(strlen("CFID=") + 10); @@ -509,6 +536,11 @@ } putenv(downsecsmsg); + alertid = make_alertid(alert->hostname, alert->testname, alert->eventstart); + alertidenv = (char *)malloc(strlen("ALERTID=") + strlen(alertid) + 10); + sprintf(alertidenv, "ALERTID=%s", alertid); + putenv(alertidenv); + hinfo = hostinfo(alert->hostname); if (hinfo) { enum bbh_item_t walk;