@cryptotaxi247 / netdata-1 / commits / 3296f7843

Add localhost hostname to the edit_command (#11793)

* include localhost hostname in edit_command * since the edit_command now contains the localhost name, dont pass it again to the script

Emmanuel Vasilakis committed Jan 17, 2022 at 12:32 UTC 3296f78436ce1f474cd38de7e842df6cf2f1f112
5 files changed +11 -23
database/sqlite/sqlite_aclk_alert.c
+2 -2
@@ -209,7 +209,7 @@ void aclk_push_alert_event(struct aclk_database_worker_config *wc, struct aclk_d
209
210 char *edit_command = sqlite3_column_bytes(res, 16) > 0 ?
211 health_edit_command_from_source((char *)sqlite3_column_text(res, 16)) :
212 - strdupz("UNKNOWN=0");
212 + strdupz("UNKNOWN=0=UNKNOWN");
213 alarm_log.command = strdupz(edit_command);
214
215 alarm_log.duration = (time_t) sqlite3_column_int64(res, 6);
@@ -695,7 +695,7 @@ void aclk_mark_alert_cloud_ack(char *uuid_str, uint64_t alerts_ack_sequence_id)
695 #ifdef ENABLE_NEW_CLOUD_PROTOCOL
696 void health_alarm_entry2proto_nolock(struct alarm_log_entry *alarm_log, ALARM_ENTRY *ae, RRDHOST *host)
697 {
698 - char *edit_command = ae->source ? health_edit_command_from_source(ae->source) : strdupz("UNKNOWN=0");
698 + char *edit_command = ae->source ? health_edit_command_from_source(ae->source) : strdupz("UNKNOWN=0=UNKNOWN");
699 char config_hash_id[GUID_LEN + 1];
700 uuid_unparse_lower(ae->config_hash_id, config_hash_id);
701
health/health.c
+3 -4
@@ -350,9 +350,9 @@ static inline void health_alarm_execute(RRDHOST *host, ALARM_ENTRY *ae) {
350 }
351 }
352
353 - char *edit_command = ae->source ? health_edit_command_from_source(ae->source) : strdupz("UNKNOWN=0");
353 + char *edit_command = ae->source ? health_edit_command_from_source(ae->source) : strdupz("UNKNOWN=0=UNKNOWN");
354
355 - snprintfz(command_to_run, ALARM_EXEC_COMMAND_LENGTH, "exec %s '%s' '%s' '%u' '%u' '%u' '%lu' '%s' '%s' '%s' '%s' '%s' '" CALCULATED_NUMBER_FORMAT_ZERO "' '" CALCULATED_NUMBER_FORMAT_ZERO "' '%s' '%u' '%u' '%s' '%s' '%s' '%s' '%s' '%s' '%d' '%d' '%s' '%s' '%s' '%s' '%s'",
355 + snprintfz(command_to_run, ALARM_EXEC_COMMAND_LENGTH, "exec %s '%s' '%s' '%u' '%u' '%u' '%lu' '%s' '%s' '%s' '%s' '%s' '" CALCULATED_NUMBER_FORMAT_ZERO "' '" CALCULATED_NUMBER_FORMAT_ZERO "' '%s' '%u' '%u' '%s' '%s' '%s' '%s' '%s' '%s' '%d' '%d' '%s' '%s' '%s' '%s'",
356 exec,
357 recipient,
358 host->registry_hostname,
@@ -381,8 +381,7 @@ static inline void health_alarm_execute(RRDHOST *host, ALARM_ENTRY *ae) {
381 buffer_tostring(warn_alarms),
382 buffer_tostring(crit_alarms),
383 ae->classification?ae->classification:"Unknown",
384 - edit_command,
385 - localhost->registry_hostname
384 + edit_command
385 );
386
387 ae->flags |= HEALTH_ENTRY_FLAG_EXEC_RUN;
health/health_config.c
+3 -2
@@ -485,10 +485,11 @@ char *health_edit_command_from_source(const char *source)
485 snprintfz(
486 buffer,
487 FILENAME_MAX,
488 - "sudo %s/edit-config health.d/%s=%s",
488 + "sudo %s/edit-config health.d/%s=%s=%s",
489 netdata_configured_user_config_dir,
490 file_no_path + 1,
491 - temp);
491 + temp,
492 + localhost->registry_hostname);
493 } else
494 buffer[0] = '\0';
495
health/health_json.c
+1 -1
@@ -14,7 +14,7 @@ void health_string2json(BUFFER *wb, const char *prefix, const char *label, const
14 }
15
16 void health_alarm_entry2json_nolock(BUFFER *wb, ALARM_ENTRY *ae, RRDHOST *host) {
17 - char *edit_command = ae->source ? health_edit_command_from_source(ae->source) : strdupz("UNKNOWN=0");
17 + char *edit_command = ae->source ? health_edit_command_from_source(ae->source) : strdupz("UNKNOWN=0=UNKNOWN");
18 char config_hash_id[GUID_LEN + 1];
19 uuid_unparse_lower(ae->config_hash_id, config_hash_id);
20
health/notifications/alarm-notify.sh.in
+2 -14
@@ -243,7 +243,6 @@ else
243 total_crit_alarms="${26}" # List of alarms in critical state
244 classification="${27}" # The class field from .conf files
245 edit_command_line="${28}" # The command to edit the alarm, with the line number
246 - sender_host="${29}" # The host sending this notification
246 fi
247
248 # -----------------------------------------------------------------------------
@@ -257,17 +256,6 @@ else
256 host="${args_host}"
257 fi
258
260 -# -----------------------------------------------------------------------------
261 -# Do the same for sender_host (find a suitable hostname to use, if netdata did not supply a hostname)
262 -
263 -if [ -z ${sender_host} ]; then
264 - this_host=$(hostname -s 2>/dev/null)
265 - s_host="${this_host}"
266 - sender_host="${this_host}"
267 -else
268 - s_host="${sender_host}"
269 -fi
270 -
259 # -----------------------------------------------------------------------------
260 # screen statuses we don't need to send a notification
261
@@ -2856,7 +2844,7 @@ if [ -n "$total_crit_alarms" ]; then
2844 fi
2845
2846 if [ -n "$edit_command_line" ]; then
2859 - IFS='=' read -r edit_command line <<<"$edit_command_line"
2847 + IFS='=' read -r edit_command line s_host <<<"$edit_command_line"
2848 fi
2849
2850 IFS='' read -r -d '' email_html_part <<EOF
@@ -3340,7 +3328,7 @@ Content-Transfer-Encoding: 8bit
3328 <tr>
3329 <td align="left" style="font-size:0px;padding:10px 25px;padding-top:8px;padding-left:0;word-break:break-word;">
3330 <div style="font-family:Open Sans, sans-serif;font-size:12px;line-height:1.3;text-align:left;color:#35414A;">${edit_command} <br>
3343 - The alarm to edit is at line {${line}}</div>
3331 + <br>The alarm to edit is at line ${line}</div>
3332 </td>
3333 </tr>
3334 </tbody>