]> andersk Git - moira.git/blame - clients/mrcheck/mrcheck.c
Win32 portability mods for Pismere.
[moira.git] / clients / mrcheck / mrcheck.c
CommitLineData
c441a31a 1/* $Id$
8ed18d22 2 *
7ac48069 3 * Verify that all Moira updates are successful
8ed18d22 4 *
7ac48069 5 * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
7 * <mit-copyright.h>.
8ed18d22 8 */
9
7ac48069 10#include <mit-copyright.h>
8fcf8fa6 11#include <moira.h>
12#include <moira_site.h>
2a12a5ec 13#include <mrclient.h>
7ac48069 14
15#include <stdio.h>
5eaef520 16#include <stdlib.h>
f071d8a7 17#include <string.h>
5eaef520 18#include <time.h>
8ed18d22 19
7ac48069 20RCSID("$Header$");
21
22char *atot(char *itime);
23int process_server(int argc, char **argv, void *sqv);
24void disp_svc(char **argv, char *msg);
25int process_host(int argc, char **argv, void *sqv);
26void disp_sh(char **argv, char *msg);
3f738519 27void usage(void);
7ac48069 28
2a12a5ec 29char *whoami;
9e3a2d47 30static int count = 0;
533bacb3 31static time_t now;
8ed18d22 32
9e3a2d47 33struct service {
5eaef520 34 char name[17];
35 char update_int[10];
9e3a2d47 36};
37
38
5eaef520 39/* turn an ascii string containing the number of seconds since the epoch
9e3a2d47 40 * into an ascii string containing the corresponding time & date
41 */
42
5eaef520 43char *atot(char *itime)
8ed18d22 44{
5eaef520 45 time_t time;
46 char *ct;
8ed18d22 47
5eaef520 48 time = atoi(itime);
49 ct = ctime(&time);
50 ct[24] = 0;
51 return &ct[4];
8ed18d22 52}
53
9e3a2d47 54
55/* Decide if the server has an error or not. Also, save the name and
56 * interval for later use.
57 */
58
7ac48069 59int process_server(int argc, char **argv, void *sqv)
8ed18d22 60{
5eaef520 61 struct service *s;
7ac48069 62 struct save_queue *sq = sqv;
5eaef520 63
64 if (atoi(argv[SVC_ENABLE]))
65 {
66 s = malloc(sizeof(struct service));
67 strcpy(s->name, argv[SVC_SERVICE]);
68 strcpy(s->update_int, argv[SVC_INTERVAL]);
69 sq_save_data(sq, s);
9e3a2d47 70 }
71
5eaef520 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])
533bacb3 79 < now)
5eaef520 80 disp_svc(argv, "Service has not been updated\n");
81
82 return MR_CONT;
8ed18d22 83}
84
9e3a2d47 85
86/* Format the information about a service. */
87
7ac48069 88void disp_svc(char **argv, char *msg)
8ed18d22 89{
7ac48069 90 char *tmp = strdup(atot(argv[SVC_DFGEN]));
5eaef520 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++;
103 free(tmp);
8ed18d22 104}
105
9e3a2d47 106
5eaef520 107/* Decide if the host has an error or not. */
9e3a2d47 108
7ac48069 109int process_host(int argc, char **argv, void *sqv)
8ed18d22 110{
5eaef520 111 struct service *s = NULL;
7ac48069 112 struct save_queue *sq = sqv, *sq1;
5eaef520 113 char *update_int = NULL;
9e3a2d47 114
5eaef520 115 for (sq1 = sq->q_next; sq1 != sq; sq1 = sq1->q_next)
116 {
9e3a2d47 117 if ((s = (struct service *)sq1->q_data) &&
118 !strcmp(s->name, argv[SH_SERVICE]))
119 break;
9e3a2d47 120 }
5eaef520 121 if (s && !strcmp(s->name, argv[SH_SERVICE]))
122 update_int = s->update_int;
123
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])
533bacb3 131 < now)
5eaef520 132 disp_sh(argv, "Host has not been updated\n");
133
134 return MR_CONT;
8ed18d22 135}
136
8ed18d22 137
9e3a2d47 138/* Format the information about a host. */
139
7ac48069 140void disp_sh(char **argv, char *msg)
9e3a2d47 141{
7ac48069 142 char *tmp = strdup(atot(argv[SH_LASTTRY]));
5eaef520 143
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);
156 count++;
157 free(tmp);
9e3a2d47 158}
159
160
161
5eaef520 162int main(int argc, char *argv[])
8ed18d22 163{
2a12a5ec 164 char *args[2], buf[BUFSIZ];
5eaef520 165 struct save_queue *sq;
166 int status;
5eaef520 167 int auth_required = 1;
168
169 if ((whoami = strrchr(argv[0], '/')) == NULL)
170 whoami = argv[0];
171 else
172 whoami++;
173
174 if (argc == 2 && !strcmp(argv[1], "-noauth"))
175 auth_required = 0;
176 else if (argc > 1)
177 usage();
178
acde26f0 179 if (mrcl_connect(NULL, NULL, 2, 0) != MRCL_SUCCESS)
2a12a5ec 180 exit(2);
5eaef520 181 status = mr_auth("mrcheck");
182 if (status && auth_required)
183 {
184 sprintf(buf, "\nAuthorization failure -- run \"kinit\" and try again");
185 goto punt;
8ed18d22 186 }
187
533bacb3 188 now = time(NULL);
5eaef520 189 sq = sq_create();
8ed18d22 190
5eaef520 191 /* Check services first */
192 args[0] = "*";
7ac48069 193 if ((status = mr_query("get_server_info", 1, args, process_server, sq)) &&
5eaef520 194 status != MR_NO_MATCH)
195 com_err(whoami, status, " while getting servers");
8ed18d22 196
5eaef520 197 args[1] = "*";
7ac48069 198 if ((status = mr_query("get_server_host_info", 2, args, process_host, sq)) &&
5eaef520 199 status != MR_NO_MATCH)
200 com_err(whoami, status, " while getting servers");
8ed18d22 201
5eaef520 202 if (!count)
203 printf("Nothing has failed at this time\n");
204 else
205 printf("%d thing%s ha%s failed at this time\n", count,
206 count == 1 ? "" : "s", count == 1 ? "s" : "ve");
8ed18d22 207
5eaef520 208 mr_disconnect();
209 exit(0);
8ed18d22 210
211punt:
5eaef520 212 com_err(whoami, status, buf);
213 mr_disconnect();
214 exit(1);
8ed18d22 215}
216
3f738519 217void usage(void)
8ed18d22 218{
5eaef520 219 fprintf(stderr, "Usage: %s [-noauth]\n", whoami);
220 exit(1);
8ed18d22 221}
This page took 0.124899 seconds and 5 git commands to generate.