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