summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmmanuel Vasilakis <mrzammler@mm.st>2022-01-17 12:32:44 +0200
committerGitHub <noreply@github.com>2022-01-17 12:32:44 +0200
commit3296f78436ce1f474cd38de7e842df6cf2f1f112 (patch)
tree935e5d9a8d1a9c3f5e96442a952f9af1698df96a
parent8c201ccadf298ccea5cc85a3aede72f8e3843fed (diff)
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
-rw-r--r--database/sqlite/sqlite_aclk_alert.c4
-rw-r--r--health/health.c7
-rw-r--r--health/health_config.c5
-rw-r--r--health/health_json.c2
-rwxr-xr-xhealth/notifications/alarm-notify.sh.in16
5 files changed, 11 insertions, 23 deletions
diff --git a/database/sqlite/sqlite_aclk_alert.c b/database/sqlite/sqlite_aclk_alert.c
index f09b2dcac8..d57783ae43 100644
--- a/database/sqlite/sqlite_aclk_alert.c
+++ b/database/sqlite/sqlite_aclk_alert.c
@@ -209,7 +209,7 @@ void aclk_push_alert_event(struct aclk_database_worker_config *wc, struct aclk_d
char *edit_command = sqlite3_column_bytes(res, 16) > 0 ?
health_edit_command_from_source((char *)sqlite3_column_text(res, 16)) :
- strdupz("UNKNOWN=0");
+ strdupz("UNKNOWN=0=UNKNOWN");
alarm_log.command = strdupz(edit_command);
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)
#ifdef ENABLE_NEW_CLOUD_PROTOCOL
void health_alarm_entry2proto_nolock(struct alarm_log_entry *alarm_log, ALARM_ENTRY *ae, RRDHOST *host)
{
- char *edit_command = ae->source ? health_edit_command_from_source(ae->source) : strdupz("UNKNOWN=0");
+ char *edit_command = ae->source ? health_edit_command_from_source(ae->source) : strdupz("UNKNOWN=0=UNKNOWN");
char config_hash_id[GUID_LEN + 1];
uuid_unparse_lower(ae->config_hash_id, config_hash_id);
diff --git a/health/health.c b/health/health.c
index 820af93f38..7bb05233cd 100644
--- a/health/health.c
+++ b/health/health.c
@@ -350,9 +350,9 @@ static inline void health_alarm_execute(RRDHOST *host, ALARM_ENTRY *ae) {
}
}
- char *edit_command = ae->source ? health_edit_command_from_source(ae->source) : strdupz("UNKNOWN=0");
+ char *edit_command = ae->source ? health_edit_command_from_source(ae->source) : strdupz("UNKNOWN=0=UNKNOWN");
- 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'",
+ 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'",
exec,
recipient,
host->registry_hostname,
@@ -381,8 +381,7 @@ static inline void health_alarm_execute(RRDHOST *host, ALARM_ENTRY *ae) {
buffer_tostring(warn_alarms),
buffer_tostring(crit_alarms),
ae->classification?ae->classification:"Unknown",
- edit_command,
- localhost->registry_hostname
+ edit_command
);
ae->flags |= HEALTH_ENTRY_FLAG_EXEC_RUN;
diff --git a/health/health_config.c b/health/health_config.c
index 35234df157..da71f13d84 100644
--- a/health/health_config.c
+++ b/health/health_config.c
@@ -485,10 +485,11 @@ char *health_edit_command_from_source(const char *source)
snprintfz(
buffer,
FILENAME_MAX,
- "sudo %s/edit-config health.d/%s=%s",
+ "sudo %s/edit-config health.d/%s=%s=%s",
netdata_configured_user_config_dir,
file_no_path + 1,
- temp);
+ temp,
+ localhost->registry_hostname);
} else
buffer[0] = '\0';
diff --git a/health/health_json.c b/health/health_json.c
index a21d5a4fd6..be95100bc2 100644
--- a/health/health_json.c
+++ b/health/health_json.c
@@ -14,7 +14,7 @@ void health_string2json(BUFFER *wb, const char *prefix, const char *label, const
}
void health_alarm_entry2json_nolock(BUFFER *wb, ALARM_ENTRY *ae, RRDHOST *host) {
- char *edit_command = ae->source ? health_edit_command_from_source(ae->source) : strdupz("UNKNOWN=0");
+ char *edit_command = ae->source ? health_edit_command_from_source(ae->source) : strdupz("UNKNOWN=0=UNKNOWN");
char config_hash_id[GUID_LEN + 1];
uuid_unparse_lower(ae->config_hash_id, config_hash_id);
diff --git a/health/notifications/alarm-notify.sh.in b/health/notifications/alarm-notify.sh.in
index c9a59413c6..287cabfef1 100755
--- a/health/notifications/alarm-notify.sh.in
+++ b/health/notifications/alarm-notify.sh.in
@@ -243,7 +243,6 @@ else
total_crit_alarms="${26}" # List of alarms in critical state
classification="${27}" # The class field from .conf files
edit_command_line="${28}" # The command to edit the alarm, with the line number
- sender_host="${29}" # The host sending this notification
fi
# -----------------------------------------------------------------------------
@@ -258,17 +257,6 @@ else
fi
# -----------------------------------------------------------------------------
-# Do the same for sender_host (find a suitable hostname to use, if netdata did not supply a hostname)
-
-if [ -z ${sender_host} ]; then
- this_host=$(hostname -s 2>/dev/null)
- s_host="${this_host}"
- sender_host="${this_host}"
-else
- s_host="${sender_host}"
-fi
-
-# -----------------------------------------------------------------------------
# screen statuses we don't need to send a notification
# don't do anything if this is not WARNING, CRITICAL or CLEAR
@@ -2856,7 +2844,7 @@ if [ -n "$total_crit_alarms" ]; then
fi
if [ -n "$edit_command_line" ]; then
- IFS='=' read -r edit_command line <<<"$edit_command_line"
+ IFS='=' read -r edit_command line s_host <<<"$edit_command_line"
fi
IFS='' read -r -d '' email_html_part <<EOF
@@ -3340,7 +3328,7 @@ Content-Transfer-Encoding: 8bit
<tr>
<td align="left" style="font-size:0px;padding:10px 25px;padding-top:8px;padding-left:0;word-break:break-word;">
<div style="font-family:Open Sans, sans-serif;font-size:12px;line-height:1.3;text-align:left;color:#35414A;">${edit_command} <br>
- The alarm to edit is at line {${line}}</div>
+ <br>The alarm to edit is at line ${line}</div>
</td>
</tr>
</tbody>