2 * Verify that all MOIRA updates are successful
4 * Copyright 1988, 1991 by the Massachusetts Institute of Technology.
5 * For copying and distribution information, see the file "mit-copyright.h".
12 static char *rcsid_chsh_c = "$Header$";
17 #include <moira_site.h>
18 #include "mit-copyright.h"
26 static struct timeval now;
35 /* turn an ascii string containing the number of seconds sinc the epoch
36 * into an ascii string containing the corresponding time & date
52 /* Decide if the server has an error or not. Also, save the name and
53 * interval for later use.
56 process_server(argc, argv, sq)
59 struct save_queue *sq;
63 if (atoi(argv[SVC_ENABLE])) {
64 s = (struct service *)malloc(sizeof(struct service));
65 strcpy(s->name, argv[SVC_SERVICE]);
66 strcpy(s->update_int, argv[SVC_INTERVAL]);
70 if (atoi(argv[SVC_HARDERROR]) && atoi(argv[SVC_ENABLE])) {
71 disp_svc(argv, "Error needs to be reset\n");
72 } else if (atoi(argv[SVC_HARDERROR]) ||
73 (!atoi(argv[SVC_ENABLE]) && atoi(argv[SVC_DFCHECK]))) {
74 disp_svc(argv, "Should this be enabled?\n");
75 } else if (atoi(argv[SVC_ENABLE]) &&
76 60 * atoi(argv[SVC_INTERVAL]) + 86400 + atoi(argv[SVC_DFCHECK])
78 disp_svc(argv, "Service has not been updated\n");
84 /* Format the information about a service. */
90 char *tmp = strsave(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.
110 process_host(argc, argv, sq)
113 struct save_queue *sq;
115 struct service *s = NULL;
116 struct save_queue *sq1;
117 char *update_int = NULL;
119 for (sq1 = sq->q_next; sq1 != sq; sq1 = sq1->q_next)
120 if ((s = (struct service *)sq1->q_data) &&
121 !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. */
146 char *tmp = strsave(atot(argv[SH_LASTTRY]));
148 printf("Host %s:%s %s/%s/%s/%s/%s %s\n",
149 argv[SH_SERVICE], argv[SH_MACHINE],
150 atoi(argv[SH_ENABLE]) ? "Enabled" : "Disabled",
151 atoi(argv[SH_SUCCESS]) ? "Success" : "Failure",
152 atoi(argv[SH_INPROGRESS]) ? "InProgress" : "Idle",
153 atoi(argv[SH_OVERRIDE]) ? "Override" : "Normal",
154 atoi(argv[SH_HOSTERROR]) ? "Error" : "NoError",
155 atoi(argv[SH_HOSTERROR]) ? argv[SH_ERRMSG] : "");
156 printf(" Last try %s; Last success %s\n", tmp, atot(argv[SH_LASTSUCCESS]));
157 printf(" Last modified by %s at %s with %s\n",
158 argv[SH_MODBY], argv[SH_MODTIME], argv[SH_MODWITH]);
159 printf(" * %s\n", msg);
171 char *args[2], buf[BUFSIZ], *motd;
172 struct save_queue *sq;
175 int auth_required = 1;
177 if ((whoami = strrchr(argv[0], '/')) == NULL)
182 if (argc == 2 && !strcmp(argv[1], "-noauth"))
187 status = mr_connect(NULL);
189 (void) sprintf(buf, "\nConnection to the Moira server failed.");
193 status = mr_motd(&motd);
195 com_err(whoami, status, " unable to check server status");
199 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n",
204 status = mr_auth("mrcheck");
205 if (status && auth_required) {
206 (void) sprintf(buf, "\nAuthorization failure -- run \"kinit\" \
211 gettimeofday(&now, 0);
214 /* Check services first */
216 if ((status = mr_query("get_server_info", 1, args,
217 process_server, (char *)sq)) &&
218 status != MR_NO_MATCH)
219 com_err(whoami, status, " while getting servers");
222 if ((status = mr_query("get_server_host_info", 2, args,
223 process_host, (char *)sq)) &&
224 status != MR_NO_MATCH)
225 com_err(whoami, status, " while getting servers");
228 printf("Nothing has failed at this time\n");
230 printf("%d thing%s ha%s failed at this time\n", count,
231 count == 1 ? "" : "s", count == 1 ? "s" : "ve");
237 com_err(whoami, status, buf);
246 "Update to Moira returned a value -- programmer botch.\n");
253 fprintf(stderr, "Usage: %s [-noauth]\n", whoami);