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;
34 /* turn an ascii string containing the number of seconds since the epoch
35 * into an ascii string containing the corresponding time & date
38 char *atot(char *itime)
50 /* Decide if the server has an error or not. Also, save the name and
51 * interval for later use.
54 int process_server(int argc, char **argv, struct save_queue *sq)
58 if (atoi(argv[SVC_ENABLE]))
60 s = malloc(sizeof(struct service));
61 strcpy(s->name, argv[SVC_SERVICE]);
62 strcpy(s->update_int, argv[SVC_INTERVAL]);
66 if (atoi(argv[SVC_HARDERROR]) && atoi(argv[SVC_ENABLE]))
67 disp_svc(argv, "Error needs to be reset\n");
68 else if (atoi(argv[SVC_HARDERROR]) ||
69 (!atoi(argv[SVC_ENABLE]) && atoi(argv[SVC_DFCHECK])))
70 disp_svc(argv, "Should this be enabled?\n");
71 else if (atoi(argv[SVC_ENABLE]) &&
72 60 * atoi(argv[SVC_INTERVAL]) + 86400 + atoi(argv[SVC_DFCHECK])
74 disp_svc(argv, "Service has not been updated\n");
80 /* Format the information about a service. */
82 int disp_svc(char **argv, char *msg)
84 char *tmp = strsave(atot(argv[SVC_DFGEN]));
86 printf("Service %s Interval %s %s/%s/%s %s\n",
87 argv[SVC_SERVICE], argv[SVC_INTERVAL],
88 atoi(argv[SVC_ENABLE]) ? "Enabled" : "Disabled",
89 atoi(argv[SVC_INPROGRESS]) ? "InProgress" : "Idle",
90 atoi(argv[SVC_HARDERROR]) ? "Error" : "NoError",
91 atoi(argv[SVC_HARDERROR]) ? argv[SVC_ERRMSG] : "");
92 printf(" Generated %s; Last checked %s\n", tmp, atot(argv[SVC_DFCHECK]));
93 printf(" Last modified by %s at %s with %s\n",
94 argv[SVC_MODBY], argv[SVC_MODTIME], argv[SVC_MODWITH]);
95 printf(" * %s\n", msg);
101 /* Decide if the host has an error or not. */
103 int process_host(int argc, char **argv, struct save_queue *sq)
105 struct service *s = NULL;
106 struct save_queue *sq1;
107 char *update_int = NULL;
109 for (sq1 = sq->q_next; sq1 != sq; sq1 = sq1->q_next)
111 if ((s = (struct service *)sq1->q_data) &&
112 !strcmp(s->name, argv[SH_SERVICE]))
115 if (s && !strcmp(s->name, argv[SH_SERVICE]))
116 update_int = s->update_int;
118 if (atoi(argv[SH_HOSTERROR]) && atoi(argv[SH_ENABLE]))
119 disp_sh(argv, "Error needs to be reset\n");
120 else if (atoi(argv[SH_HOSTERROR]) ||
121 (!atoi(argv[SH_ENABLE]) && atoi(argv[SH_LASTTRY])))
122 disp_sh(argv, "Should this be enabled?\n");
123 else if (atoi(argv[SH_ENABLE]) && update_int &&
124 60 * atoi(update_int) + 86400 + atoi(argv[SH_LASTSUCCESS])
126 disp_sh(argv, "Host has not been updated\n");
132 /* Format the information about a host. */
134 int disp_sh(char **argv, char *msg)
136 char *tmp = strsave(atot(argv[SH_LASTTRY]));
138 printf("Host %s:%s %s/%s/%s/%s/%s %s\n",
139 argv[SH_SERVICE], argv[SH_MACHINE],
140 atoi(argv[SH_ENABLE]) ? "Enabled" : "Disabled",
141 atoi(argv[SH_SUCCESS]) ? "Success" : "Failure",
142 atoi(argv[SH_INPROGRESS]) ? "InProgress" : "Idle",
143 atoi(argv[SH_OVERRIDE]) ? "Override" : "Normal",
144 atoi(argv[SH_HOSTERROR]) ? "Error" : "NoError",
145 atoi(argv[SH_HOSTERROR]) ? argv[SH_ERRMSG] : "");
146 printf(" Last try %s; Last success %s\n", tmp, atot(argv[SH_LASTSUCCESS]));
147 printf(" Last modified by %s at %s with %s\n",
148 argv[SH_MODBY], argv[SH_MODTIME], argv[SH_MODWITH]);
149 printf(" * %s\n", msg);
156 int main(int argc, char *argv[])
158 char *args[2], buf[BUFSIZ], *motd;
159 struct save_queue *sq;
162 int auth_required = 1;
164 if ((whoami = strrchr(argv[0], '/')) == NULL)
169 if (argc == 2 && !strcmp(argv[1], "-noauth"))
174 status = mr_connect(NULL);
177 sprintf(buf, "\nConnection to the Moira server failed.");
181 status = mr_motd(&motd);
184 com_err(whoami, status, " unable to check server status");
189 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n",
194 status = mr_auth("mrcheck");
195 if (status && auth_required)
197 sprintf(buf, "\nAuthorization failure -- run \"kinit\" and try again");
201 gettimeofday(&now, 0);
204 /* Check services first */
206 if ((status = mr_query("get_server_info", 1, args,
207 process_server, (char *)sq)) &&
208 status != MR_NO_MATCH)
209 com_err(whoami, status, " while getting servers");
212 if ((status = mr_query("get_server_host_info", 2, args,
213 process_host, (char *)sq)) &&
214 status != MR_NO_MATCH)
215 com_err(whoami, status, " while getting servers");
218 printf("Nothing has failed at this time\n");
220 printf("%d thing%s ha%s failed at this time\n", count,
221 count == 1 ? "" : "s", count == 1 ? "s" : "ve");
227 com_err(whoami, status, buf);
236 "Update to Moira returned a value -- programmer botch.\n");
243 fprintf(stderr, "Usage: %s [-noauth]\n", whoami);