This source file includes following definitions.
- status2char
- event2status
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 #include <string.h>
23 #include <stdio.h>
24 #include <time.h>
25 #include <errno.h>
26 #include <servicelog.h>
27 #include <syslog.h>
28 #include <unistd.h>
29 #include <config.h>
30 #include <crm/common/xml.h>
31 #include <crm/common/util.h>
32 #include <crm_internal.h>
33
34 typedef enum { STATUS_GREEN = 1, STATUS_YELLOW, STATUS_RED } STATUS;
35
36 const char *status2char(STATUS status);
37 STATUS event2status(struct sl_event *event);
38
39 const char *
40 status2char(STATUS status)
41 {
42 switch (status) {
43 default:
44 case STATUS_GREEN:
45 return "green";
46 case STATUS_YELLOW:
47 return "yellow";
48 case STATUS_RED:
49 return "red";
50 }
51 }
52
53 STATUS
54 event2status(struct sl_event * event)
55 {
56 STATUS status = STATUS_GREEN;
57
58 crm_debug("Severity = %d, Disposition = %d", event->severity, event->disposition);
59
60
61 if (event->severity == SL_SEV_WARNING) {
62 status = STATUS_YELLOW;
63 }
64
65 if (event->disposition == SL_DISP_UNRECOVERABLE) {
66 status = STATUS_RED;
67 }
68
69 return status;
70 }
71
72 static struct crm_option long_options[] = {
73
74 {"help", 0, 0, '?', "\tThis text"},
75 {"version", 0, 0, '$', "\tVersion information"},
76 {"-spacer-", 0, 0, '-', "\nUsage: notifyServicelogEvent event_id"},
77 {"-spacer-", 0, 0, '-',
78 "\nWhere event_id is unique unsigned event identifier which is then passed into servicelog"},
79
80 {0, 0, 0, 0}
81 };
82
83 int
84 main(int argc, char *argv[])
85 {
86 int argerr = 0;
87 int flag;
88 int index = 0;
89 int rc = 0;
90 servicelog *slog = NULL;
91 struct sl_event *event = NULL;
92 uint64_t event_id = 0;
93
94 crm_log_init_quiet("notifyServicelogEvent", LOG_INFO, FALSE, TRUE, argc, argv);
95 crm_set_options(NULL, "event_id ", long_options,
96 "Gets called upon events written to servicelog database");
97
98 if (argc < 2) {
99 argerr++;
100 }
101
102 while (1) {
103 flag = crm_get_option(argc, argv, &index);
104 if (flag == -1)
105 break;
106
107 switch (flag) {
108 case '?':
109 case '$':
110 crm_help(flag, 0);
111 break;
112 default:
113 ++argerr;
114 break;
115 }
116 }
117
118 if (argc - optind != 1) {
119 ++argerr;
120 }
121
122 if (argerr) {
123 crm_help('?', 1);
124 }
125
126 openlog("notifyServicelogEvent", LOG_NDELAY, LOG_USER);
127
128 if (sscanf(argv[optind], U64T, &event_id) != 1) {
129 crm_err("Error: could not read event_id from args!");
130
131 rc = 1;
132 goto cleanup;
133 }
134
135 if (event_id == 0) {
136 crm_err("Error: event_id is 0!");
137
138 rc = 1;
139 goto cleanup;
140 }
141
142 rc = servicelog_open(&slog, 0);
143
144 if (!slog) {
145 crm_err("Error: servicelog_open failed, rc = %d", rc);
146
147 rc = 1;
148 goto cleanup;
149 }
150
151 if (slog) {
152 rc = servicelog_event_get(slog, event_id, &event);
153 }
154
155 if (rc == 0) {
156 STATUS status = STATUS_GREEN;
157 const char *health_component = "#health-ipmi";
158 const char *health_status = NULL;
159
160 crm_debug("Event id = " U64T ", Log timestamp = %s, Event timestamp = %s",
161 event_id, ctime(&(event->time_logged)), ctime(&(event->time_event)));
162
163 status = event2status(event);
164
165 health_status = status2char(status);
166
167 if (health_status) {
168 gboolean rc;
169
170
171 rc = (attrd_update_delegate(NULL, 'v', NULL, health_component,
172 health_status, NULL, NULL, NULL, NULL,
173 attrd_opt_none) > 0);
174 crm_debug("Updating attribute ('%s', '%s') = %d",
175 health_component, health_status, rc);
176 } else {
177 crm_err("Error: status2char failed, status = %d", status);
178 rc = 1;
179 }
180 } else {
181 crm_err("Error: servicelog_event_get failed, rc = %d", rc);
182 }
183
184 cleanup:
185 if (event) {
186 servicelog_event_free(event);
187 }
188
189 if (slog) {
190 servicelog_close(slog);
191 }
192
193 closelog();
194
195 return rc;
196 }