3 * Verify that all Moira updates are successful
5 * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
10 #include <mit-copyright.h>
12 #include <moira_site.h>
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);
33 static struct timeval now;
41 /* turn an ascii string containing the number of seconds since the epoch
42 * into an ascii string containing the corresponding time & date
45 char *atot(char *itime)
57 /* Decide if the server has an error or not. Also, save the name and
58 * interval for later use.
61 int process_server(int argc, char **argv, void *sqv)
64 struct save_queue *sq = sqv;
66 if (atoi(argv[SVC_ENABLE]))
68 s = malloc(sizeof(struct service));
69 strcpy(s->name, argv[SVC_SERVICE]);
70 strcpy(s->update_int, argv[SVC_INTERVAL]);
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])
82 disp_svc(argv, "Service has not been updated\n");
88 /* Format the information about a service. */
90 void disp_svc(char **argv, char *msg)
92 char *tmp = strdup(atot(argv[SVC_DFGEN]));
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);
109 /* Decide if the host has an error or not. */
111 int process_host(int argc, char **argv, void *sqv)
113 struct service *s = NULL;
114 struct save_queue *sq = sqv, *sq1;
115 char *update_int = NULL;
117 for (sq1 = sq->q_next; sq1 != sq; sq1 = sq1->q_next)
119 if ((s = (struct service *)sq1->q_data) &&
120 !strcmp(s->name, argv[SH_SERVICE]))
123 if (s && !strcmp(s->name, argv[SH_SERVICE]))
124 update_int = s->update_int;
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])
134 disp_sh(argv, "Host has not been updated\n");
140 /* Format the information about a host. */
142 void disp_sh(char **argv, char *msg)
144 char *tmp = strdup(atot(argv[SH_LASTTRY]));
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);
164 int main(int argc, char *argv[])
166 char *args[2], buf[BUFSIZ];
167 struct save_queue *sq;
169 int auth_required = 1;
171 if ((whoami = strrchr(argv[0], '/')) == NULL)
176 if (argc == 2 && !strcmp(argv[1], "-noauth"))
181 if (mrcl_connect(NULL, NULL, 2, 0) != MRCL_SUCCESS)
183 status = mr_auth("mrcheck");
184 if (status && auth_required)
186 sprintf(buf, "\nAuthorization failure -- run \"kinit\" and try again");
190 gettimeofday(&now, 0);
193 /* Check services first */
195 if ((status = mr_query("get_server_info", 1, args, process_server, sq)) &&
196 status != MR_NO_MATCH)
197 com_err(whoami, status, " while getting servers");
200 if ((status = mr_query("get_server_host_info", 2, args, process_host, sq)) &&
201 status != MR_NO_MATCH)
202 com_err(whoami, status, " while getting servers");
205 printf("Nothing has failed at this time\n");
207 printf("%d thing%s ha%s failed at this time\n", count,
208 count == 1 ? "" : "s", count == 1 ? "s" : "ve");
214 com_err(whoami, status, buf);
221 fprintf(stderr, "Usage: %s [-noauth]\n", whoami);