]>
Commit | Line | Data |
---|---|---|
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 | |
ca3ab839 | 15 | #include <sys/time.h> |
16 | ||
7ac48069 | 17 | #include <stdio.h> |
5eaef520 | 18 | #include <stdlib.h> |
f071d8a7 | 19 | #include <string.h> |
5eaef520 | 20 | #include <time.h> |
8ed18d22 | 21 | |
7ac48069 | 22 | RCSID("$Header$"); |
23 | ||
24 | char *atot(char *itime); | |
25 | int process_server(int argc, char **argv, void *sqv); | |
26 | void disp_svc(char **argv, char *msg); | |
27 | int process_host(int argc, char **argv, void *sqv); | |
28 | void disp_sh(char **argv, char *msg); | |
3f738519 | 29 | void usage(void); |
7ac48069 | 30 | |
2a12a5ec | 31 | char *whoami; |
9e3a2d47 | 32 | static int count = 0; |
9e3a2d47 | 33 | static struct timeval now; |
8ed18d22 | 34 | |
9e3a2d47 | 35 | struct service { |
5eaef520 | 36 | char name[17]; |
37 | char update_int[10]; | |
9e3a2d47 | 38 | }; |
39 | ||
40 | ||
5eaef520 | 41 | /* turn an ascii string containing the number of seconds since the epoch |
9e3a2d47 | 42 | * into an ascii string containing the corresponding time & date |
43 | */ | |
44 | ||
5eaef520 | 45 | char *atot(char *itime) |
8ed18d22 | 46 | { |
5eaef520 | 47 | time_t time; |
48 | char *ct; | |
8ed18d22 | 49 | |
5eaef520 | 50 | time = atoi(itime); |
51 | ct = ctime(&time); | |
52 | ct[24] = 0; | |
53 | return &ct[4]; | |
8ed18d22 | 54 | } |
55 | ||
9e3a2d47 | 56 | |
57 | /* Decide if the server has an error or not. Also, save the name and | |
58 | * interval for later use. | |
59 | */ | |
60 | ||
7ac48069 | 61 | int process_server(int argc, char **argv, void *sqv) |
8ed18d22 | 62 | { |
5eaef520 | 63 | struct service *s; |
7ac48069 | 64 | struct save_queue *sq = sqv; |
5eaef520 | 65 | |
66 | if (atoi(argv[SVC_ENABLE])) | |
67 | { | |
68 | s = malloc(sizeof(struct service)); | |
69 | strcpy(s->name, argv[SVC_SERVICE]); | |
70 | strcpy(s->update_int, argv[SVC_INTERVAL]); | |
71 | sq_save_data(sq, s); | |
9e3a2d47 | 72 | } |
73 | ||
5eaef520 | 74 | if (atoi(argv[SVC_HARDERROR]) && atoi(argv[SVC_ENABLE])) |
75 | disp_svc(argv, "Error needs to be reset\n"); | |
76 | else if (atoi(argv[SVC_HARDERROR]) || | |
77 | (!atoi(argv[SVC_ENABLE]) && atoi(argv[SVC_DFCHECK]))) | |
78 | disp_svc(argv, "Should this be enabled?\n"); | |
79 | else if (atoi(argv[SVC_ENABLE]) && | |
80 | 60 * atoi(argv[SVC_INTERVAL]) + 86400 + atoi(argv[SVC_DFCHECK]) | |
81 | < now.tv_sec) | |
82 | disp_svc(argv, "Service has not been updated\n"); | |
83 | ||
84 | return MR_CONT; | |
8ed18d22 | 85 | } |
86 | ||
9e3a2d47 | 87 | |
88 | /* Format the information about a service. */ | |
89 | ||
7ac48069 | 90 | void disp_svc(char **argv, char *msg) |
8ed18d22 | 91 | { |
7ac48069 | 92 | char *tmp = strdup(atot(argv[SVC_DFGEN])); |
5eaef520 | 93 | |
94 | printf("Service %s Interval %s %s/%s/%s %s\n", | |
95 | argv[SVC_SERVICE], argv[SVC_INTERVAL], | |
96 | atoi(argv[SVC_ENABLE]) ? "Enabled" : "Disabled", | |
97 | atoi(argv[SVC_INPROGRESS]) ? "InProgress" : "Idle", | |
98 | atoi(argv[SVC_HARDERROR]) ? "Error" : "NoError", | |
99 | atoi(argv[SVC_HARDERROR]) ? argv[SVC_ERRMSG] : ""); | |
100 | printf(" Generated %s; Last checked %s\n", tmp, atot(argv[SVC_DFCHECK])); | |
101 | printf(" Last modified by %s at %s with %s\n", | |
102 | argv[SVC_MODBY], argv[SVC_MODTIME], argv[SVC_MODWITH]); | |
103 | printf(" * %s\n", msg); | |
104 | count++; | |
105 | free(tmp); | |
8ed18d22 | 106 | } |
107 | ||
9e3a2d47 | 108 | |
5eaef520 | 109 | /* Decide if the host has an error or not. */ |
9e3a2d47 | 110 | |
7ac48069 | 111 | int process_host(int argc, char **argv, void *sqv) |
8ed18d22 | 112 | { |
5eaef520 | 113 | struct service *s = NULL; |
7ac48069 | 114 | struct save_queue *sq = sqv, *sq1; |
5eaef520 | 115 | char *update_int = NULL; |
9e3a2d47 | 116 | |
5eaef520 | 117 | for (sq1 = sq->q_next; sq1 != sq; sq1 = sq1->q_next) |
118 | { | |
9e3a2d47 | 119 | if ((s = (struct service *)sq1->q_data) && |
120 | !strcmp(s->name, argv[SH_SERVICE])) | |
121 | break; | |
9e3a2d47 | 122 | } |
5eaef520 | 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 | ||
136 | return MR_CONT; | |
8ed18d22 | 137 | } |
138 | ||
8ed18d22 | 139 | |
9e3a2d47 | 140 | /* Format the information about a host. */ |
141 | ||
7ac48069 | 142 | void disp_sh(char **argv, char *msg) |
9e3a2d47 | 143 | { |
7ac48069 | 144 | char *tmp = strdup(atot(argv[SH_LASTTRY])); |
5eaef520 | 145 | |
146 | printf("Host %s:%s %s/%s/%s/%s/%s %s\n", | |
147 | argv[SH_SERVICE], argv[SH_MACHINE], | |
148 | atoi(argv[SH_ENABLE]) ? "Enabled" : "Disabled", | |
149 | atoi(argv[SH_SUCCESS]) ? "Success" : "Failure", | |
150 | atoi(argv[SH_INPROGRESS]) ? "InProgress" : "Idle", | |
151 | atoi(argv[SH_OVERRIDE]) ? "Override" : "Normal", | |
152 | atoi(argv[SH_HOSTERROR]) ? "Error" : "NoError", | |
153 | atoi(argv[SH_HOSTERROR]) ? argv[SH_ERRMSG] : ""); | |
154 | printf(" Last try %s; Last success %s\n", tmp, atot(argv[SH_LASTSUCCESS])); | |
155 | printf(" Last modified by %s at %s with %s\n", | |
156 | argv[SH_MODBY], argv[SH_MODTIME], argv[SH_MODWITH]); | |
157 | printf(" * %s\n", msg); | |
158 | count++; | |
159 | free(tmp); | |
9e3a2d47 | 160 | } |
161 | ||
162 | ||
163 | ||
5eaef520 | 164 | int main(int argc, char *argv[]) |
8ed18d22 | 165 | { |
2a12a5ec | 166 | char *args[2], buf[BUFSIZ]; |
5eaef520 | 167 | struct save_queue *sq; |
168 | int status; | |
5eaef520 | 169 | int auth_required = 1; |
170 | ||
171 | if ((whoami = strrchr(argv[0], '/')) == NULL) | |
172 | whoami = argv[0]; | |
173 | else | |
174 | whoami++; | |
175 | ||
176 | if (argc == 2 && !strcmp(argv[1], "-noauth")) | |
177 | auth_required = 0; | |
178 | else if (argc > 1) | |
179 | usage(); | |
180 | ||
2a12a5ec | 181 | if (mrcl_connect(NULL, NULL, 0) != MRCL_SUCCESS) |
182 | exit(2); | |
5eaef520 | 183 | status = mr_auth("mrcheck"); |
184 | if (status && auth_required) | |
185 | { | |
186 | sprintf(buf, "\nAuthorization failure -- run \"kinit\" and try again"); | |
187 | goto punt; | |
8ed18d22 | 188 | } |
189 | ||
5eaef520 | 190 | gettimeofday(&now, 0); |
191 | sq = sq_create(); | |
8ed18d22 | 192 | |
5eaef520 | 193 | /* Check services first */ |
194 | args[0] = "*"; | |
7ac48069 | 195 | if ((status = mr_query("get_server_info", 1, args, process_server, sq)) && |
5eaef520 | 196 | status != MR_NO_MATCH) |
197 | com_err(whoami, status, " while getting servers"); | |
8ed18d22 | 198 | |
5eaef520 | 199 | args[1] = "*"; |
7ac48069 | 200 | if ((status = mr_query("get_server_host_info", 2, args, process_host, sq)) && |
5eaef520 | 201 | status != MR_NO_MATCH) |
202 | com_err(whoami, status, " while getting servers"); | |
8ed18d22 | 203 | |
5eaef520 | 204 | if (!count) |
205 | printf("Nothing has failed at this time\n"); | |
206 | else | |
207 | printf("%d thing%s ha%s failed at this time\n", count, | |
208 | count == 1 ? "" : "s", count == 1 ? "s" : "ve"); | |
8ed18d22 | 209 | |
5eaef520 | 210 | mr_disconnect(); |
211 | exit(0); | |
8ed18d22 | 212 | |
213 | punt: | |
5eaef520 | 214 | com_err(whoami, status, buf); |
215 | mr_disconnect(); | |
216 | exit(1); | |
8ed18d22 | 217 | } |
218 | ||
3f738519 | 219 | void usage(void) |
8ed18d22 | 220 | { |
5eaef520 | 221 | fprintf(stderr, "Usage: %s [-noauth]\n", whoami); |
222 | exit(1); | |
8ed18d22 | 223 | } |