]> andersk Git - moira.git/blob - clients/mrcheck/mrcheck.c
570508f18665cc0a04631983b2357e7575878062
[moira.git] / clients / mrcheck / mrcheck.c
1 /*
2  * Verify that all SMS updates are successful
3  *
4  * Copyright 1988 by the Massachusetts Institute of Technology. For copying
5  * and distribution information, see the file "mit-copyright.h". 
6  *
7  * $Source$
8  * $Header$
9  * $Author$
10  */
11
12 #ifndef lint
13 static char *rcsid_chsh_c = "$Header$";
14 #endif  lint
15
16 #include <stdio.h>
17 #include <sms.h>
18 #include <sms_app.h>
19 #include "mit-copyright.h"
20
21 char *malloc(), *rindex(), *strsave();
22
23 static int status;
24 static char *whoami;
25
26
27 char *atot(itime)
28 char *itime;
29 {
30     int time;
31     char *ct, *ctime();
32
33     time = atoi(itime);
34     ct = ctime(&time);
35     ct[24] = 0;
36     return(&ct[4]);
37 }
38
39 gserv(argc, argv, sq)
40 int argc;
41 char **argv;
42 struct save_queue *sq;
43 {
44     char *tmp;
45
46     tmp = strsave(atot(argv[4]));
47     printf("Service %s, error %s: %s\n\tlast success %s, last try %s\n",
48            argv[0], argv[9], argv[10], tmp, atot(argv[5]));
49     free(tmp);
50     return(SMS_CONT);
51 }
52
53 ghost(argc, argv, sq)
54 int argc;
55 char **argv;
56 struct save_queue *sq;
57 {
58     char *tmp;
59
60     tmp = strsave(atot(argv[9]));
61     printf("Host %s:%s, error %s: %s\n\tlast success %s, last try %s\n",
62            argv[0], argv[1], argv[6], argv[7], tmp, atot(argv[8]));
63     free(tmp);
64     return(SMS_CONT);
65 }
66
67 save_args(argc, argv, sq)
68 int argc;
69 char **argv;
70 struct save_queue *sq;
71 {
72     sq_save_args(argc, argv, sq);
73     return(SMS_CONT);
74 }
75
76 main(argc, argv)
77     char *argv[];
78
79 {
80     char *args[6], buf[BUFSIZ], **service, **host;
81     struct save_queue *services, *hosts;
82     int count = 0, scream();
83
84     if ((whoami = rindex(argv[0], '/')) == NULL)
85         whoami = argv[0];
86     else
87         whoami++;
88
89     if (argc > 1) {
90         usage();
91     }
92
93     status = sms_connect(SMS_SERVER);
94     if (status) {
95         (void) sprintf(buf, "\nConnection to the SMS server failed.");
96         goto punt;
97     }
98
99     status = sms_auth("smscheck");
100     if (status) {
101         (void) sprintf(buf, "\nAuthorization failure -- run \"kinit\" \
102 and try again");
103         goto punt;
104     }
105
106     services = sq_create();
107     args[0] = args[2] = "TRUE";
108     args[1] = "DONTCARE";
109     if ((status = sms_query("qualified_get_server", 3, args, save_args,
110                             (char *)services)) &&
111         status != SMS_NO_MATCH)
112       com_err(whoami, status, " while getting servers");
113
114     hosts = sq_create();
115     args[0] = "*";
116     args[1] = args[5] = "TRUE";
117     args[2] = args[3] = args[4] = "DONTCARE";
118     if ((status = sms_query("qualified_get_server_host", 6, args, save_args,
119                             (char *)hosts)) &&
120         status != SMS_NO_MATCH)
121       com_err(whoami, status, " while getting server/hosts");
122
123     while (sq_get_data(services, &service)) {
124         count++;
125         if (status = sms_query("get_server_info", 1, service, gserv, NULL))
126           com_err(whoami, status, " while getting info about service %s",
127                   service[0]);
128     }
129
130     while (sq_get_data(hosts, &host)) {
131         count++; 
132         if (status = sms_query("get_server_host_info", 2, host, ghost, NULL))
133           com_err(whoami, status, " while getting info about host %s:%s",
134                   host[0], host[1]);
135    }
136
137     if (!count)
138       strcpy(buf, "Nothing has failed at this time");
139     else
140       sprintf(buf, "%d thing%s ha%s failed at this time", count,
141               count == 1 ? "" : "s", count == 1 ? "s" : "ve");
142     puts(buf);
143
144     sms_disconnect();
145     exit(0);
146
147 punt:
148     com_err(whoami, status, buf);
149     sms_disconnect();
150     exit(1);
151 }
152
153
154 scream()
155 {
156     com_err(whoami, status, "Update to SMS returned a value -- \
157 programmer botch.\n");
158     sms_disconnect();
159     exit(1);
160 }
161
162 usage()
163 {
164     fprintf(stderr, "Usage: %s\n", whoami);
165     exit(1);
166 }
This page took 0.038709 seconds and 3 git commands to generate.