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