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>
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);
30 static struct timeval now;
38 /* turn an ascii string containing the number of seconds since the epoch
39 * into an ascii string containing the corresponding time & date
42 char *atot(char *itime)
54 /* Decide if the server has an error or not. Also, save the name and
55 * interval for later use.
58 int process_server(int argc, char **argv, void *sqv)
61 struct save_queue *sq = sqv;
63 if (atoi(argv[SVC_ENABLE]))
65 s = malloc(sizeof(struct service));
66 strcpy(s->name, argv[SVC_SERVICE]);
67 strcpy(s->update_int, argv[SVC_INTERVAL]);
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])
79 disp_svc(argv, "Service has not been updated\n");
85 /* Format the information about a service. */
87 void disp_svc(char **argv, char *msg)
89 char *tmp = strdup(atot(argv[SVC_DFGEN]));
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);
106 /* Decide if the host has an error or not. */
108 int process_host(int argc, char **argv, void *sqv)
110 struct service *s = NULL;
111 struct save_queue *sq = sqv, *sq1;
112 char *update_int = NULL;
114 for (sq1 = sq->q_next; sq1 != sq; sq1 = sq1->q_next)
116 if ((s = (struct service *)sq1->q_data) &&
117 !strcmp(s->name, argv[SH_SERVICE]))
120 if (s && !strcmp(s->name, argv[SH_SERVICE]))
121 update_int = s->update_int;
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])
131 disp_sh(argv, "Host has not been updated\n");
137 /* Format the information about a host. */
139 void disp_sh(char **argv, char *msg)
141 char *tmp = strdup(atot(argv[SH_LASTTRY]));
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);
161 int main(int argc, char *argv[])
163 char *args[2], buf[BUFSIZ], *motd;
164 struct save_queue *sq;
166 int auth_required = 1;
168 if ((whoami = strrchr(argv[0], '/')) == NULL)
173 if (argc == 2 && !strcmp(argv[1], "-noauth"))
178 status = mr_connect(NULL);
181 sprintf(buf, "\nConnection to the Moira server failed.");
185 status = mr_motd(&motd);
188 com_err(whoami, status, " unable to check server status");
193 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n",
198 status = mr_auth("mrcheck");
199 if (status && auth_required)
201 sprintf(buf, "\nAuthorization failure -- run \"kinit\" and try again");
205 gettimeofday(&now, 0);
208 /* Check services first */
210 if ((status = mr_query("get_server_info", 1, args, process_server, sq)) &&
211 status != MR_NO_MATCH)
212 com_err(whoami, status, " while getting servers");
215 if ((status = mr_query("get_server_host_info", 2, args, process_host, sq)) &&
216 status != MR_NO_MATCH)
217 com_err(whoami, status, " while getting servers");
220 printf("Nothing has failed at this time\n");
222 printf("%d thing%s ha%s failed at this time\n", count,
223 count == 1 ? "" : "s", count == 1 ? "s" : "ve");
229 com_err(whoami, status, buf);
236 fprintf(stderr, "Usage: %s [-noauth]\n", whoami);