netdata now sets NETDATA_HOSTNAME, NETDATA_REGISTRY_HOSTNAME, NETDATA_REGISTRY_URL, NETDATA_REGISTRY_UNIQUE_ID
Costa Tsaousis committed
Aug 25, 2016 at 13:31 UTC
8f345346006ad3c500c08e0e2641765cb3a8e590
5 files changed
+37
-12
plugins.d/alarm-email.sh
+20
-8
@@ -23,16 +23,21 @@ sendmail_from_pipe() {
23
24
name="${1}" # the name of the alarm, as given in netdata health.d entries
25
chart="${2}" # the name of the chart (type.id)
26
-status="${3}" # the current status : UNITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
27
-old_status="${4}" # the previous status: UNITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
28
-value="${5}" # the current value
29
-old_value="${6}" # the previous value
30
-src="${7}" # the line number and file the alarm has been configured
31
-duration="${8}" # the duration in seconds the previous state took
32
-non_clear_duration="${9}" # the total duration in seconds this is non-clear
26
+family="${3}" # the family of the chart
27
+status="${4}" # the current status : UNITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
28
+old_status="${5}" # the previous status: UNITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
29
+value="${6}" # the current value
30
+old_value="${7}" # the previous value
31
+src="${8}" # the line number and file the alarm has been configured
32
+duration="${9}" # the duration in seconds the previous state took
33
+non_clear_duration="${10}" # the total duration in seconds this is non-clear
34
35
# get the system hostname
35
-hostname="$(hostname)"
36
+hostname="${NETDATA_HOSTNAME}"
37
+[ -z "${hostname}" ] && hostname="${NETDATA_REGISTRY_HOSTNAME}"
38
+[ -z "${hostname}" ] && hostname="$(hostname)"
39
+
40
+goto_url="${NETDATA_REGISTRY_URL}/alarmcallback.html?machine_guid=${NETDATA_REGISTRY_UNIQUE_ID}&chart=${chart}&family=${family}"
41
42
# get the current date
43
date="$(date)"
@@ -213,6 +218,13 @@ Content-Type: text/html
218
style="display:block;color:#666666;font-size:12px;font-weight:300;line-height:1;text-transform:uppercase">Time</span>
219
</td>
220
</tr>
221
+ <!--
222
+ <tr style="margin:0;padding:0">
223
+ <td style="font-size:18px;vertical-align:top;margin:0;padding:0 0 20px">
224
+ <a href="${goto_url}" style="font-size:14px;color:#ffffff;text-decoration:none;line-height:1.5;font-weight:bold;text-align:center;display:inline-block;text-transform:capitalize;background:#35568d;border-width:1px;border-style:solid;border-color:#2b4c86;margin:0;padding:10px 15px" target="_blank">View Netdata</a>
225
+ </td>
226
+ </tr>
227
+ -->
228
<tr style="text-align:center;margin:0;padding:0">
229
<td style="font-size:11px;vertical-align:top;margin:0;padding:10px 0 0 0;color:#666666"
230
align="center" valign="bottom">The source of this alarm is line <code>${src}</code>
src/health.c
+9
-4
@@ -1610,10 +1610,11 @@ static inline void health_alarm_execute(ALARM_ENTRY *ae) {
1610
const char *exec = ae->exec;
1611
if(!exec) exec = health_default_exec;
1612
1613
- snprintfz(buffer, FILENAME_MAX, "exec %s '%s' '%s' '%s' '%s' '%0.0Lf' '%0.0Lf' '%s' '%u' '%u'",
1613
+ snprintfz(buffer, FILENAME_MAX, "exec %s '%s' '%s' '%s' '%s' '%s' '%0.0Lf' '%0.0Lf' '%s' '%u' '%u'",
1614
exec,
1615
ae->name,
1616
ae->chart?ae->chart:"NOCAHRT",
1617
+ ae->family?ae->family:"NOFAMILY",
1618
rrdcalc_status2string(ae->new_status),
1619
rrdcalc_status2string(ae->old_status),
1620
ae->new_value,
@@ -1649,8 +1650,8 @@ static inline void health_process_notifications(ALARM_ENTRY *ae) {
1650
}
1651
1652
static inline void health_alarm_log(time_t when,
1652
- const char *name, const char *chart, const char *exec,
1653
- time_t duration,
1653
+ const char *name, const char *chart, const char *family,
1654
+ const char *exec, time_t duration,
1655
calculated_number old_value, calculated_number new_value,
1656
int old_status, int new_status,
1657
const char *source
@@ -1664,6 +1665,9 @@ static inline void health_alarm_log(time_t when,
1665
ae->hash_chart = simple_hash(ae->chart);
1666
}
1667
1668
+ if(family)
1669
+ ae->family = strdupz(family);
1670
+
1671
if(exec) ae->exec = strdupz(exec);
1672
if(source) ae->source = strdupz(source);
1673
@@ -1738,6 +1742,7 @@ static inline void health_alarm_log_process(void) {
1742
while(ae) {
1743
ALARM_ENTRY *t = ae->next;
1744
1745
+ freez(ae->family);
1746
freez(ae->chart);
1747
freez(ae->name);
1748
freez(ae->exec);
@@ -1979,7 +1984,7 @@ void *health_main(void *ptr) {
1984
}
1985
1986
if(status != rc->status) {
1982
- health_alarm_log(time(NULL), rc->name, rc->rrdset->id, rc->exec, now - rc->last_status_change, rc->old_value, rc->value, rc->status, status, rc->source);
1987
+ health_alarm_log(time(NULL), rc->name, rc->rrdset->id, rc->rrdset->family, rc->exec, now - rc->last_status_change, rc->old_value, rc->value, rc->status, status, rc->source);
1988
rc->last_status_change = now;
1989
rc->status = status;
1990
}
src/health.h
+2
@@ -222,6 +222,8 @@ typedef struct alarm_entry {
222
char *chart;
223
uint32_t hash_chart;
224
225
+ char *family;
226
+
227
char *exec;
228
char *source;
229
calculated_number old_value;
src/main.c
+1
@@ -501,6 +501,7 @@ int main(int argc, char **argv)
501
error("WARNING: Cannot get machine hostname.");
502
hostname = config_get("global", "hostname", hostnamebuf);
503
debug(D_OPTIONS, "hostname set to '%s'", hostname);
504
+ setenv("NETDATA_HOSTNAME", hostname, 1);
505
}
506
507
// --------------------------------------------------------------------
src/registry.c
+5
@@ -1268,6 +1268,8 @@ char *registry_get_this_machine_guid(void) {
1268
close(fd);
1269
}
1270
1271
+ setenv("NETDATA_REGISTRY_UNIQUE_ID", registry.machine_guid, 1);
1272
+
1273
return registry.machine_guid;
1274
}
1275
@@ -1636,6 +1638,9 @@ int registry_init(void) {
1638
registry.hostname = config_get("registry", "registry hostname", config_get("global", "hostname", hostname));
1639
registry.verify_cookies_redirects = config_get_boolean("registry", "verify browser cookies support", 1);
1640
1641
+ setenv("NETDATA_REGISTRY_HOSTNAME", registry.hostname, 1);
1642
+ setenv("NETDATA_REGISTRY_URL", registry.registry_to_announce, 1);
1643
+
1644
registry.max_url_length = config_get_number("registry", "max URL length", 1024);
1645
if(registry.max_url_length < 10) {
1646
registry.max_url_length = 10;