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