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>
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);
39 /* turn an ascii string containing the number of seconds since the epoch
40 * into an ascii string containing the corresponding time & date
43 char *atot(char *itime)
55 /* Decide if the server has an error or not. Also, save the name and
56 * interval for later use.
59 int process_server(int argc, char **argv, void *sqv)
62 struct save_queue *sq = sqv;
64 if (atoi(argv[SVC_ENABLE]))
66 s = malloc(sizeof(struct service));
67 strcpy(s->name, argv[SVC_SERVICE]);
68 strcpy(s->update_int, argv[SVC_INTERVAL]);
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])
80 disp_svc(argv, "Service has not been updated\n");
86 /* Format the information about a service. */
88 void disp_svc(char **argv, char *msg)
90 char *tmp = strdup(atot(argv[SVC_DFGEN]));
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);
107 /* Decide if the host has an error or not. */
109 int process_host(int argc, char **argv, void *sqv)
111 struct service *s = NULL;
112 struct save_queue *sq = sqv, *sq1;
113 char *update_int = NULL;
115 for (sq1 = sq->q_next; sq1 != sq; sq1 = sq1->q_next)
117 if ((s = (struct service *)sq1->q_data) &&
118 !strcmp(s->name, argv[SH_SERVICE]))
121 if (s && !strcmp(s->name, argv[SH_SERVICE]))
122 update_int = s->update_int;
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])
132 disp_sh(argv, "Host has not been updated\n");
138 /* Format the information about a host. */
140 void disp_sh(char **argv, char *msg)
142 char *tmp = strdup(atot(argv[SH_LASTTRY]));
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);
162 int main(int argc, char *argv[])
164 char *args[2], buf[BUFSIZ];
165 struct save_queue *sq;
167 int auth_required = 1;
169 if ((whoami = strrchr(argv[0], '/')) == NULL)
174 if (argc == 2 && !strcmp(argv[1], "-noauth"))
179 if (mrcl_connect(NULL, NULL, 2, 0) != MRCL_SUCCESS)
181 status = mr_auth("mrcheck");
182 if (status && auth_required)
184 sprintf(buf, "\nAuthorization failure -- run \"kinit\" and try again");
191 /* Check services first */
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");
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");
203 printf("Nothing has failed at this time\n");
205 printf("%d thing%s ha%s failed at this time\n", count,
206 count == 1 ? "" : "s", count == 1 ? "s" : "ve");
212 com_err(whoami, status, buf);
219 fprintf(stderr, "Usage: %s [-noauth]\n", whoami);