]> andersk Git - moira.git/blame - clients/mrcheck/mrcheck.c
cant_fix takes an argument
[moira.git] / clients / mrcheck / mrcheck.c
CommitLineData
8ed18d22 1/*
8fcf8fa6 2 * Verify that all MOIRA updates are successful
8ed18d22 3 *
9e3a2d47 4 * Copyright 1988, 1991 by the Massachusetts Institute of Technology.
5 * For copying and distribution information, see the file "mit-copyright.h".
8ed18d22 6 *
8ed18d22 7 * $Header$
8 * $Author$
9 */
10
11#ifndef lint
12static char *rcsid_chsh_c = "$Header$";
67562db4 13#endif
8ed18d22 14
15#include <stdio.h>
8fcf8fa6 16#include <moira.h>
17#include <moira_site.h>
8ed18d22 18#include "mit-copyright.h"
9e3a2d47 19#include <sys/time.h>
f071d8a7 20#include <string.h>
8ed18d22 21
9e3a2d47 22char *malloc();
8ed18d22 23
9e3a2d47 24static int count = 0;
8ed18d22 25static char *whoami;
9e3a2d47 26static struct timeval now;
8ed18d22 27
28
9e3a2d47 29struct service {
30 char name[17];
31 char update_int[10];
32};
33
34
35/* turn an ascii string containing the number of seconds sinc the epoch
36 * into an ascii string containing the corresponding time & date
37 */
38
8ed18d22 39char *atot(itime)
40char *itime;
41{
67562db4 42 time_t time;
8ed18d22 43 char *ct, *ctime();
44
45 time = atoi(itime);
46 ct = ctime(&time);
47 ct[24] = 0;
48 return(&ct[4]);
49}
50
9e3a2d47 51
52/* Decide if the server has an error or not. Also, save the name and
53 * interval for later use.
54 */
55
56process_server(argc, argv, sq)
8ed18d22 57int argc;
58char **argv;
59struct save_queue *sq;
60{
9e3a2d47 61 struct service *s;
8ed18d22 62
9e3a2d47 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]);
67 sq_save_data(sq, s);
68 }
69
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])
77 < now.tv_sec) {
78 disp_svc(argv, "Service has not been updated\n");
79 }
8fcf8fa6 80 return(MR_CONT);
8ed18d22 81}
82
9e3a2d47 83
84/* Format the information about a service. */
85
86disp_svc(argv, msg)
8ed18d22 87char **argv;
9e3a2d47 88char *msg;
8ed18d22 89{
9e3a2d47 90 char *tmp = strsave(atot(argv[SVC_DFGEN]));
91
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);
102 count++;
8ed18d22 103 free(tmp);
8ed18d22 104}
105
9e3a2d47 106
107/* Decide if the host has an error or not.
108 */
109
110process_host(argc, argv, sq)
8ed18d22 111int argc;
112char **argv;
113struct save_queue *sq;
114{
9e3a2d47 115 struct service *s = NULL;
116 struct save_queue *sq1;
117 char *update_int = NULL;
118
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]))
122 break;
123 if (s && !strcmp(s->name, argv[SH_SERVICE]))
124 update_int = s->update_int;
125
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])
133 < now.tv_sec) {
134 disp_sh(argv, "Host has not been updated\n");
135 }
8fcf8fa6 136 return(MR_CONT);
8ed18d22 137}
138
8ed18d22 139
9e3a2d47 140/* Format the information about a host. */
141
142disp_sh(argv, msg)
143char **argv;
144char *msg;
145{
146 char *tmp = strsave(atot(argv[SH_LASTTRY]));
147
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);
160 count++;
161 free(tmp);
162}
163
164
165
166
167main(argc, argv)
168int argc;
169char *argv[];
8ed18d22 170{
9e3a2d47 171 char *args[2], buf[BUFSIZ], *motd;
172 struct save_queue *sq;
173 int status;
174 int scream();
66ec6010 175 int auth_required = 1;
8ed18d22 176
f071d8a7 177 if ((whoami = strrchr(argv[0], '/')) == NULL)
8ed18d22 178 whoami = argv[0];
179 else
180 whoami++;
181
66ec6010 182 if (argc == 2 && !strcmp(argv[1], "-noauth"))
183 auth_required = 0;
184 else if (argc > 1)
185 usage();
8ed18d22 186
8fcf8fa6 187 status = mr_connect(NULL);
8ed18d22 188 if (status) {
95cd286e 189 (void) sprintf(buf, "\nConnection to the Moira server failed.");
8ed18d22 190 goto punt;
191 }
192
8fcf8fa6 193 status = mr_motd(&motd);
262ca740 194 if (status) {
195 com_err(whoami, status, " unable to check server status");
196 exit(2);
197 }
198 if (motd) {
9e3a2d47 199 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n",
200 motd);
8fcf8fa6 201 mr_disconnect();
262ca740 202 exit(2);
203 }
8fcf8fa6 204 status = mr_auth("mrcheck");
66ec6010 205 if (status && auth_required) {
8ed18d22 206 (void) sprintf(buf, "\nAuthorization failure -- run \"kinit\" \
207and try again");
208 goto punt;
209 }
210
9e3a2d47 211 gettimeofday(&now, 0);
212 sq = sq_create();
8ed18d22 213
9e3a2d47 214 /* Check services first */
8ed18d22 215 args[0] = "*";
9e3a2d47 216 if ((status = mr_query("get_server_info", 1, args,
217 process_server, (char *)sq)) &&
8fcf8fa6 218 status != MR_NO_MATCH)
9e3a2d47 219 com_err(whoami, status, " while getting servers");
8ed18d22 220
9e3a2d47 221 args[1] = "*";
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");
8ed18d22 226
227 if (!count)
9e3a2d47 228 printf("Nothing has failed at this time\n");
8ed18d22 229 else
9e3a2d47 230 printf("%d thing%s ha%s failed at this time\n", count,
231 count == 1 ? "" : "s", count == 1 ? "s" : "ve");
8ed18d22 232
8fcf8fa6 233 mr_disconnect();
8ed18d22 234 exit(0);
235
236punt:
237 com_err(whoami, status, buf);
8fcf8fa6 238 mr_disconnect();
8ed18d22 239 exit(1);
240}
241
242
243scream()
244{
9e3a2d47 245 com_err(whoami, 0,
246 "Update to Moira returned a value -- programmer botch.\n");
8fcf8fa6 247 mr_disconnect();
8ed18d22 248 exit(1);
249}
250
251usage()
252{
66ec6010 253 fprintf(stderr, "Usage: %s [-noauth]\n", whoami);
8ed18d22 254 exit(1);
255}
This page took 0.116177 seconds and 5 git commands to generate.