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