summaryrefslogtreecommitdiffstats
path: root/health
diff options
context:
space:
mode:
authorEmmanuel Vasilakis <mrzammler@mm.st>2021-05-31 16:29:47 +0300
committerGitHub <noreply@github.com>2021-05-31 16:29:47 +0300
commit9f40c4b12c1047c3489ba07dcf1c1e9b647d1835 (patch)
tree2c9b9aaa1bd19b9a7e5f84e7b4488345039190ab /health
parent5bce2d9a8196a90e9d3972b90934d79bad4bb8e1 (diff)
Provide UTC offset in seconds and edit health config command (#11051)
* add abbreviated timezone, utc offset in seconds, and edit health alarm command rebased * formating * use str2i instead of atoi
Diffstat (limited to 'health')
-rw-r--r--health/health.h2
-rw-r--r--health/health_config.c23
-rw-r--r--health/health_json.c9
3 files changed, 34 insertions, 0 deletions
diff --git a/health/health.h b/health/health.h
index 0a6d3e0dc9..e7408f632d 100644
--- a/health/health.h
+++ b/health/health.h
@@ -96,6 +96,8 @@ extern void *health_cmdapi_thread(void *ptr);
extern void health_label_log_save(RRDHOST *host);
+extern char *health_edit_command_from_source(const char *source);
+
extern SIMPLE_PATTERN *health_pattern_from_foreach(char *s);
#endif //NETDATA_HEALTH_H
diff --git a/health/health_config.c b/health/health_config.c
index 756023715e..a79f727aae 100644
--- a/health/health_config.c
+++ b/health/health_config.c
@@ -473,6 +473,29 @@ static inline char *health_source_file(size_t line, const char *file) {
return strdupz(buffer);
}
+char *health_edit_command_from_source(const char *source)
+{
+ char buffer[FILENAME_MAX + 1];
+ char *temp = strdupz(source);
+ char *line_num = strchr(temp, '@');
+ char *file_no_path = strrchr(temp, '/');
+
+ if (likely(file_no_path && line_num)) {
+ *line_num = '\0';
+ snprintfz(
+ buffer,
+ FILENAME_MAX,
+ "sudo %s/edit-config health.d/%s=%s",
+ netdata_configured_user_config_dir,
+ file_no_path + 1,
+ temp);
+ } else
+ buffer[0] = '\0';
+
+ freez(temp);
+ return strdupz(buffer);
+}
+
static inline void strip_quotes(char *s) {
while(*s) {
if(*s == '\'' || *s == '"') *s = ' ';
diff --git a/health/health_json.c b/health/health_json.c
index 4df44611ca..d3c3073215 100644
--- a/health/health_json.c
+++ b/health/health_json.c
@@ -14,9 +14,13 @@ 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");
+
buffer_sprintf(wb,
"\n\t{\n"
"\t\t\"hostname\": \"%s\",\n"
+ "\t\t\"utc_offset\": %d,\n"
+ "\t\t\"timezone\": \"%s\",\n"
"\t\t\"unique_id\": %u,\n"
"\t\t\"alarm_id\": %u,\n"
"\t\t\"alarm_event_id\": %u,\n"
@@ -34,6 +38,7 @@ void health_alarm_entry2json_nolock(BUFFER *wb, ALARM_ENTRY *ae, RRDHOST *host)
"\t\t\"recipient\": \"%s\",\n"
"\t\t\"exec_code\": %d,\n"
"\t\t\"source\": \"%s\",\n"
+ "\t\t\"command\": \"%s\",\n"
"\t\t\"units\": \"%s\",\n"
"\t\t\"when\": %lu,\n"
"\t\t\"duration\": %lu,\n"
@@ -49,6 +54,8 @@ void health_alarm_entry2json_nolock(BUFFER *wb, ALARM_ENTRY *ae, RRDHOST *host)
"\t\t\"last_repeat\": \"%lu\",\n"
"\t\t\"silenced\": \"%s\",\n"
, host->hostname
+ , host->utc_offset
+ , host->abbrev_timezone
, ae->unique_id
, ae->alarm_id
, ae->alarm_event_id
@@ -66,6 +73,7 @@ void health_alarm_entry2json_nolock(BUFFER *wb, ALARM_ENTRY *ae, RRDHOST *host)
, ae->recipient?ae->recipient:host->health_default_recipient
, ae->exec_code
, ae->source
+ , edit_command
, ae->units?ae->units:""
, (unsigned long)ae->when
, (unsigned long)ae->duration
@@ -114,6 +122,7 @@ void health_alarm_entry2json_nolock(BUFFER *wb, ALARM_ENTRY *ae, RRDHOST *host)
buffer_strcat(wb, "\t}");
freez(replaced_info);
+ freez(edit_command);
}
void health_alarm_log2json(RRDHOST *host, BUFFER *wb, uint32_t after, char *chart) {