]> arthur.barton.de Git - netdata.git/commitdiff
netdata now sets NETDATA_HOSTNAME, NETDATA_REGISTRY_HOSTNAME, NETDATA_REGISTRY_URL...
authorCosta Tsaousis <costa@tsaousis.gr>
Thu, 25 Aug 2016 10:31:04 +0000 (13:31 +0300)
committerCosta Tsaousis <costa@tsaousis.gr>
Thu, 25 Aug 2016 10:31:04 +0000 (13:31 +0300)
plugins.d/alarm-email.sh
src/health.c
src/health.h
src/main.c
src/registry.c

index 3cc0734b0bd5637837cb5b2296f3560ad1425f07..9bfe33aaf8915c1fc64be146202f55afd4e15b21 100755 (executable)
@@ -23,16 +23,21 @@ sendmail_from_pipe() {
 
 name="${1}"       # the name of the alarm, as given in netdata health.d entries
 chart="${2}"      # the name of the chart (type.id)
-status="${3}"     # the current status : UNITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
-old_status="${4}" # the previous status: UNITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
-value="${5}"      # the current value
-old_value="${6}"  # the previous value
-src="${7}"        # the line number and file the alarm has been configured
-duration="${8}"   # the duration in seconds the previous state took
-non_clear_duration="${9}" # the total duration in seconds this is non-clear
+family="${3}"     # the family of the chart
+status="${4}"     # the current status : UNITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
+old_status="${5}" # the previous status: UNITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
+value="${6}"      # the current value
+old_value="${7}"  # the previous value
+src="${8}"        # the line number and file the alarm has been configured
+duration="${9}"   # the duration in seconds the previous state took
+non_clear_duration="${10}" # the total duration in seconds this is non-clear
 
 # get the system hostname
-hostname="$(hostname)"
+hostname="${NETDATA_HOSTNAME}"
+[ -z "${hostname}" ] && hostname="${NETDATA_REGISTRY_HOSTNAME}"
+[ -z "${hostname}" ] && hostname="$(hostname)"
+
+goto_url="${NETDATA_REGISTRY_URL}/alarmcallback.html?machine_guid=${NETDATA_REGISTRY_UNIQUE_ID}&chart=${chart}&family=${family}"
 
 # get the current date
 date="$(date)"
@@ -213,6 +218,13 @@ Content-Type: text/html
                                                     style="display:block;color:#666666;font-size:12px;font-weight:300;line-height:1;text-transform:uppercase">Time</span>
                                         </td>
                                     </tr>
+                                    <!--
+                                    <tr style="margin:0;padding:0">
+                                        <td style="font-size:18px;vertical-align:top;margin:0;padding:0 0 20px">
+                                            <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>
+                                        </td>
+                                    </tr>
+                                    -->
                                     <tr style="text-align:center;margin:0;padding:0">
                                         <td style="font-size:11px;vertical-align:top;margin:0;padding:10px 0 0 0;color:#666666"
                                             align="center" valign="bottom">The source of this alarm is line <code>${src}</code>
index 746392daeb702695f80df21d4c4b2425805d36d2..3cf9ae50a5d8ff92dd7a29b2cf63dc46e5de273d 100644 (file)
@@ -1610,10 +1610,11 @@ static inline void health_alarm_execute(ALARM_ENTRY *ae) {
     const char *exec = ae->exec;
     if(!exec) exec = health_default_exec;
 
-    snprintfz(buffer, FILENAME_MAX, "exec %s '%s' '%s' '%s' '%s' '%0.0Lf' '%0.0Lf' '%s' '%u' '%u'",
+    snprintfz(buffer, FILENAME_MAX, "exec %s '%s' '%s' '%s' '%s' '%s' '%0.0Lf' '%0.0Lf' '%s' '%u' '%u'",
               exec,
               ae->name,
               ae->chart?ae->chart:"NOCAHRT",
+              ae->family?ae->family:"NOFAMILY",
               rrdcalc_status2string(ae->new_status),
               rrdcalc_status2string(ae->old_status),
               ae->new_value,
@@ -1649,8 +1650,8 @@ static inline void health_process_notifications(ALARM_ENTRY *ae) {
 }
 
 static inline void health_alarm_log(time_t when,
-                const char *name, const char *chart, const char *exec,
-                time_t duration,
+                const char *name, const char *chart, const char *family,
+                const char *exec, time_t duration,
                 calculated_number old_value, calculated_number new_value,
                 int old_status, int new_status,
                 const char *source
@@ -1664,6 +1665,9 @@ static inline void health_alarm_log(time_t when,
         ae->hash_chart = simple_hash(ae->chart);
     }
 
+    if(family)
+        ae->family = strdupz(family);
+
     if(exec) ae->exec = strdupz(exec);
     if(source) ae->source = strdupz(source);
 
@@ -1738,6 +1742,7 @@ static inline void health_alarm_log_process(void) {
     while(ae) {
         ALARM_ENTRY *t = ae->next;
 
+        freez(ae->family);
         freez(ae->chart);
         freez(ae->name);
         freez(ae->exec);
@@ -1979,7 +1984,7 @@ void *health_main(void *ptr) {
                 }
 
                 if(status != rc->status) {
-                    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);
+                    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);
                     rc->last_status_change = now;
                     rc->status = status;
                 }
index 045ddf1a81bfa8de0728ff373dccf1ac1c3c0377..5cc9dcbdc92e602ff5c6251cecfe722c9b9bad7d 100644 (file)
@@ -222,6 +222,8 @@ typedef struct alarm_entry {
     char *chart;
     uint32_t hash_chart;
 
+    char *family;
+
     char *exec;
     char *source;
     calculated_number old_value;
index b9580b66fe52000b39a186657d87efe9fcc16491..0d504d914540570bbc6f404e5b9d98bcbea6928b 100644 (file)
@@ -501,6 +501,7 @@ int main(int argc, char **argv)
                 error("WARNING: Cannot get machine hostname.");
             hostname = config_get("global", "hostname", hostnamebuf);
             debug(D_OPTIONS, "hostname set to '%s'", hostname);
+            setenv("NETDATA_HOSTNAME", hostname, 1);
         }
 
         // --------------------------------------------------------------------
index 41e88905b5632735fd42b555125a9ac0c3cc81a4..f2319c478257128a24f421ca5969dc6e830f72cb 100644 (file)
@@ -1268,6 +1268,8 @@ char *registry_get_this_machine_guid(void) {
         close(fd);
     }
 
+    setenv("NETDATA_REGISTRY_UNIQUE_ID", registry.machine_guid, 1);
+
     return registry.machine_guid;
 }
 
@@ -1636,6 +1638,9 @@ int registry_init(void) {
     registry.hostname = config_get("registry", "registry hostname", config_get("global", "hostname", hostname));
     registry.verify_cookies_redirects = config_get_boolean("registry", "verify browser cookies support", 1);
 
+    setenv("NETDATA_REGISTRY_HOSTNAME", registry.hostname, 1);
+    setenv("NETDATA_REGISTRY_URL", registry.registry_to_announce, 1);
+
     registry.max_url_length = config_get_number("registry", "max URL length", 1024);
     if(registry.max_url_length < 10) {
         registry.max_url_length = 10;