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