]>
Commit | Line | Data |
---|---|---|
c441a31a | 1 | /* $Id$ |
8ed18d22 | 2 | * |
7ac48069 | 3 | * Verify that all Moira updates are successful |
8ed18d22 | 4 | * |
7ac48069 | 5 | * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology. |
6 | * For copying and distribution information, please see the file | |
7 | * <mit-copyright.h>. | |
8ed18d22 | 8 | */ |
9 | ||
7ac48069 | 10 | #include <mit-copyright.h> |
8fcf8fa6 | 11 | #include <moira.h> |
12 | #include <moira_site.h> | |
7ac48069 | 13 | |
ca3ab839 | 14 | #include <sys/time.h> |
15 | ||
7ac48069 | 16 | #include <stdio.h> |
5eaef520 | 17 | #include <stdlib.h> |
f071d8a7 | 18 | #include <string.h> |
5eaef520 | 19 | #include <time.h> |
8ed18d22 | 20 | |
7ac48069 | 21 | RCSID("$Header$"); |
22 | ||
23 | char *atot(char *itime); | |
24 | int process_server(int argc, char **argv, void *sqv); | |
25 | void disp_svc(char **argv, char *msg); | |
26 | int process_host(int argc, char **argv, void *sqv); | |
27 | void disp_sh(char **argv, char *msg); | |
28 | int usage(void); | |
29 | ||
9e3a2d47 | 30 | static int count = 0; |
8ed18d22 | 31 | static char *whoami; |
9e3a2d47 | 32 | static struct timeval now; |
8ed18d22 | 33 | |
9e3a2d47 | 34 | struct service { |
5eaef520 | 35 | char name[17]; |
36 | char update_int[10]; | |
9e3a2d47 | 37 | }; |
38 | ||
39 | ||
5eaef520 | 40 | /* turn an ascii string containing the number of seconds since the epoch |
9e3a2d47 | 41 | * into an ascii string containing the corresponding time & date |
42 | */ | |
43 | ||
5eaef520 | 44 | char *atot(char *itime) |
8ed18d22 | 45 | { |
5eaef520 | 46 | time_t time; |
47 | char *ct; | |
8ed18d22 | 48 | |
5eaef520 | 49 | time = atoi(itime); |
50 | ct = ctime(&time); | |
51 | ct[24] = 0; | |
52 | return &ct[4]; | |
8ed18d22 | 53 | } |
54 | ||
9e3a2d47 | 55 | |
56 | /* Decide if the server has an error or not. Also, save the name and | |
57 | * interval for later use. | |
58 | */ | |
59 | ||
7ac48069 | 60 | int process_server(int argc, char **argv, void *sqv) |
8ed18d22 | 61 | { |
5eaef520 | 62 | struct service *s; |
7ac48069 | 63 | struct save_queue *sq = sqv; |
5eaef520 | 64 | |
65 | if (atoi(argv[SVC_ENABLE])) | |
66 | { | |
67 | s = malloc(sizeof(struct service)); | |
68 | strcpy(s->name, argv[SVC_SERVICE]); | |
69 | strcpy(s->update_int, argv[SVC_INTERVAL]); | |
70 | sq_save_data(sq, s); | |
9e3a2d47 | 71 | } |
72 | ||
5eaef520 | 73 | if (atoi(argv[SVC_HARDERROR]) && atoi(argv[SVC_ENABLE])) |
74 | disp_svc(argv, "Error needs to be reset\n"); | |
75 | else if (atoi(argv[SVC_HARDERROR]) || | |
76 | (!atoi(argv[SVC_ENABLE]) && atoi(argv[SVC_DFCHECK]))) | |
77 | disp_svc(argv, "Should this be enabled?\n"); | |
78 | else if (atoi(argv[SVC_ENABLE]) && | |
79 | 60 * atoi(argv[SVC_INTERVAL]) + 86400 + atoi(argv[SVC_DFCHECK]) | |
80 | < now.tv_sec) | |
81 | disp_svc(argv, "Service has not been updated\n"); | |
82 | ||
83 | return MR_CONT; | |
8ed18d22 | 84 | } |
85 | ||
9e3a2d47 | 86 | |
87 | /* Format the information about a service. */ | |
88 | ||
7ac48069 | 89 | void disp_svc(char **argv, char *msg) |
8ed18d22 | 90 | { |
7ac48069 | 91 | char *tmp = strdup(atot(argv[SVC_DFGEN])); |
5eaef520 | 92 | |
93 | printf("Service %s Interval %s %s/%s/%s %s\n", | |
94 | argv[SVC_SERVICE], argv[SVC_INTERVAL], | |
95 | atoi(argv[SVC_ENABLE]) ? "Enabled" : "Disabled", | |
96 | atoi(argv[SVC_INPROGRESS]) ? "InProgress" : "Idle", | |
97 | atoi(argv[SVC_HARDERROR]) ? "Error" : "NoError", | |
98 | atoi(argv[SVC_HARDERROR]) ? argv[SVC_ERRMSG] : ""); | |
99 | printf(" Generated %s; Last checked %s\n", tmp, atot(argv[SVC_DFCHECK])); | |
100 | printf(" Last modified by %s at %s with %s\n", | |
101 | argv[SVC_MODBY], argv[SVC_MODTIME], argv[SVC_MODWITH]); | |
102 | printf(" * %s\n", msg); | |
103 | count++; | |
104 | free(tmp); | |
8ed18d22 | 105 | } |
106 | ||
9e3a2d47 | 107 | |
5eaef520 | 108 | /* Decide if the host has an error or not. */ |
9e3a2d47 | 109 | |
7ac48069 | 110 | int process_host(int argc, char **argv, void *sqv) |
8ed18d22 | 111 | { |
5eaef520 | 112 | struct service *s = NULL; |
7ac48069 | 113 | struct save_queue *sq = sqv, *sq1; |
5eaef520 | 114 | char *update_int = NULL; |
9e3a2d47 | 115 | |
5eaef520 | 116 | for (sq1 = sq->q_next; sq1 != sq; sq1 = sq1->q_next) |
117 | { | |
9e3a2d47 | 118 | if ((s = (struct service *)sq1->q_data) && |
119 | !strcmp(s->name, argv[SH_SERVICE])) | |
120 | break; | |
9e3a2d47 | 121 | } |
5eaef520 | 122 | if (s && !strcmp(s->name, argv[SH_SERVICE])) |
123 | update_int = s->update_int; | |
124 | ||
125 | if (atoi(argv[SH_HOSTERROR]) && atoi(argv[SH_ENABLE])) | |
126 | disp_sh(argv, "Error needs to be reset\n"); | |
127 | else if (atoi(argv[SH_HOSTERROR]) || | |
128 | (!atoi(argv[SH_ENABLE]) && atoi(argv[SH_LASTTRY]))) | |
129 | disp_sh(argv, "Should this be enabled?\n"); | |
130 | else if (atoi(argv[SH_ENABLE]) && update_int && | |
131 | 60 * atoi(update_int) + 86400 + atoi(argv[SH_LASTSUCCESS]) | |
132 | < now.tv_sec) | |
133 | disp_sh(argv, "Host has not been updated\n"); | |
134 | ||
135 | return MR_CONT; | |
8ed18d22 | 136 | } |
137 | ||
8ed18d22 | 138 | |
9e3a2d47 | 139 | /* Format the information about a host. */ |
140 | ||
7ac48069 | 141 | void disp_sh(char **argv, char *msg) |
9e3a2d47 | 142 | { |
7ac48069 | 143 | char *tmp = strdup(atot(argv[SH_LASTTRY])); |
5eaef520 | 144 | |
145 | printf("Host %s:%s %s/%s/%s/%s/%s %s\n", | |
146 | argv[SH_SERVICE], argv[SH_MACHINE], | |
147 | atoi(argv[SH_ENABLE]) ? "Enabled" : "Disabled", | |
148 | atoi(argv[SH_SUCCESS]) ? "Success" : "Failure", | |
149 | atoi(argv[SH_INPROGRESS]) ? "InProgress" : "Idle", | |
150 | atoi(argv[SH_OVERRIDE]) ? "Override" : "Normal", | |
151 | atoi(argv[SH_HOSTERROR]) ? "Error" : "NoError", | |
152 | atoi(argv[SH_HOSTERROR]) ? argv[SH_ERRMSG] : ""); | |
153 | printf(" Last try %s; Last success %s\n", tmp, atot(argv[SH_LASTSUCCESS])); | |
154 | printf(" Last modified by %s at %s with %s\n", | |
155 | argv[SH_MODBY], argv[SH_MODTIME], argv[SH_MODWITH]); | |
156 | printf(" * %s\n", msg); | |
157 | count++; | |
158 | free(tmp); | |
9e3a2d47 | 159 | } |
160 | ||
161 | ||
162 | ||
5eaef520 | 163 | int main(int argc, char *argv[]) |
8ed18d22 | 164 | { |
5eaef520 | 165 | char *args[2], buf[BUFSIZ], *motd; |
166 | struct save_queue *sq; | |
167 | int status; | |
5eaef520 | 168 | int auth_required = 1; |
169 | ||
170 | if ((whoami = strrchr(argv[0], '/')) == NULL) | |
171 | whoami = argv[0]; | |
172 | else | |
173 | whoami++; | |
174 | ||
175 | if (argc == 2 && !strcmp(argv[1], "-noauth")) | |
176 | auth_required = 0; | |
177 | else if (argc > 1) | |
178 | usage(); | |
179 | ||
180 | status = mr_connect(NULL); | |
181 | if (status) | |
182 | { | |
183 | sprintf(buf, "\nConnection to the Moira server failed."); | |
184 | goto punt; | |
8ed18d22 | 185 | } |
186 | ||
5eaef520 | 187 | status = mr_motd(&motd); |
188 | if (status) | |
189 | { | |
190 | com_err(whoami, status, " unable to check server status"); | |
191 | exit(2); | |
262ca740 | 192 | } |
5eaef520 | 193 | if (motd) |
194 | { | |
195 | fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", | |
196 | motd); | |
197 | mr_disconnect(); | |
198 | exit(2); | |
262ca740 | 199 | } |
5eaef520 | 200 | status = mr_auth("mrcheck"); |
201 | if (status && auth_required) | |
202 | { | |
203 | sprintf(buf, "\nAuthorization failure -- run \"kinit\" and try again"); | |
204 | goto punt; | |
8ed18d22 | 205 | } |
206 | ||
5eaef520 | 207 | gettimeofday(&now, 0); |
208 | sq = sq_create(); | |
8ed18d22 | 209 | |
5eaef520 | 210 | /* Check services first */ |
211 | args[0] = "*"; | |
7ac48069 | 212 | if ((status = mr_query("get_server_info", 1, args, process_server, sq)) && |
5eaef520 | 213 | status != MR_NO_MATCH) |
214 | com_err(whoami, status, " while getting servers"); | |
8ed18d22 | 215 | |
5eaef520 | 216 | args[1] = "*"; |
7ac48069 | 217 | if ((status = mr_query("get_server_host_info", 2, args, process_host, sq)) && |
5eaef520 | 218 | status != MR_NO_MATCH) |
219 | com_err(whoami, status, " while getting servers"); | |
8ed18d22 | 220 | |
5eaef520 | 221 | if (!count) |
222 | printf("Nothing has failed at this time\n"); | |
223 | else | |
224 | printf("%d thing%s ha%s failed at this time\n", count, | |
225 | count == 1 ? "" : "s", count == 1 ? "s" : "ve"); | |
8ed18d22 | 226 | |
5eaef520 | 227 | mr_disconnect(); |
228 | exit(0); | |
8ed18d22 | 229 | |
230 | punt: | |
5eaef520 | 231 | com_err(whoami, status, buf); |
232 | mr_disconnect(); | |
233 | exit(1); | |
8ed18d22 | 234 | } |
235 | ||
5eaef520 | 236 | int usage(void) |
8ed18d22 | 237 | { |
5eaef520 | 238 | fprintf(stderr, "Usage: %s [-noauth]\n", whoami); |
239 | exit(1); | |
8ed18d22 | 240 | } |