2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
15 #include <sys/types.h>
20 #include <netinet/in.h>
22 #include <afs/afsutil.h>
25 * XXX CHANGE the following depedent stuff XXX
27 #define SENDMAIL "/afs/cellname/fs/dev/localtools/dest/bin/rcs-sendmail"
29 * Replace it with a bboard (i.e. transarc.bosserver.auto-reports)
31 #define RECIPIENT "foo@cellname"
33 #include "AFS_component_version_number.c"
41 char buf[BUFSIZ], *bufp, *bufp1, *typep, *cmd, *bp;
42 afs_int32 code, c, fd, id, pflags = -1, len, core = 0, lastE = 0;
43 char comLine[60], coreName[40], name[40], lastErrorName[50];
44 afs_int32 pid = -1, lastExit = -1, lastSignal = -1, rsCount = -1;
45 afs_int32 procStarts = -1;
46 afs_int32 errorCode = -1, errorSignal = -1, goal = -1;
47 time_t procStartTime = -1, rsTime = -1, lastAnyExit = -1, lastErrorExit = -1;
50 typep = (char *)malloc(50);
51 cmd = (char *)malloc(50);
52 bufp = bufp1 = (char *)malloc(1000);
53 while (fgets(buf, sizeof(buf), fin)) {
54 code = sscanf(buf, "%s %s\n", typep, cmd);
58 if (!strcmp(typep, "BEGIN") && !strcmp(cmd, "bnode_proc")) {
59 while (fgets(buf, sizeof(buf), fin)) {
60 code = sscanf(buf, "%s %s\n", typep, cmd);
62 printf("**bnode_proc**: typed=%s, cmd=%s\n", typep, cmd);
65 if (!strcmp(typep, "comLine:"))
67 else if (!strcmp(typep, "coreName:"))
68 strcpy(coreName, cmd);
69 else if (!strcmp(typep, "pid:"))
72 else if (!strcmp(typep, "lastExit:"))
74 else if (!strcmp(typep, "lastSignal:"))
75 lastSignal = atoi(cmd);
77 else if (!strcmp(typep, "flags:"))
79 else if (!strcmp(typep, "END")) {
83 ("Unexpected token %s in the bnode_proc (should be END)\n",
88 } else if (!strcmp(typep, "BEGIN") && !strcmp(cmd, "bnode")) {
89 while (fgets(buf, sizeof(buf), fin)) {
90 code = sscanf(buf, "%s %s\n", typep, cmd);
92 printf("**bnode**: typed=%s, cmd=%s\n", typep, cmd);
95 if (!strcmp(typep, "name:"))
97 else if (!strcmp(typep, "rsTime:"))
99 else if (!strcmp(typep, "rsCount:"))
101 else if (!strcmp(typep, "procStartTime:"))
102 procStartTime = atoi(cmd);
103 else if (!strcmp(typep, "procStarts:"))
104 procStarts = atoi(cmd);
105 else if (!strcmp(typep, "lastAnyExit:"))
106 lastAnyExit = atoi(cmd);
107 else if (!strcmp(typep, "lastErrorExit:"))
108 lastErrorExit = atoi(cmd);
109 else if (!strcmp(typep, "errorCode:"))
110 errorCode = atoi(cmd);
111 else if (!strcmp(typep, "errorSignal:"))
112 errorSignal = atoi(cmd);
114 else if (!strcmp(typep, "lastErrorName:"))
115 strcpy(lastErrorName, cmd);
117 else if (!strcmp(typep, "goal:"))
119 else if (!strcmp(typep, "END")) {
123 ("Unexpected token %s in the bnode (should be END)\n",
129 printf("Unexpected token %s (should be BEGIN)\n", typep);
134 * Now make up the text for the post
136 sprintf(buf, "/tmp/snote.%d", getpid());
137 fd = open(buf, O_RDWR | O_CREAT | O_TRUNC, 0600);
140 printf("Unable to create temp file, %s\n", buf);
143 (void)sprintf(bufp, "Subject: Bosserver's automatic notification\n\n");
144 bufp += strlen(bufp);
146 "AUTOMATIC NOTIFICATION EVENT FOR AFS SERVER INSTANCE %s\n\n",
148 bufp += strlen(bufp);
149 (void)sprintf(bufp, "Server Process id was: %d\n", pid);
150 bufp += strlen(bufp);
151 (void)sprintf(bufp, "Server command line: %s\n", comLine);
152 bufp += strlen(bufp);
153 if (strcmp(coreName, "(null)"))
156 strcpy(bp, AFSDIR_SERVER_CORELOG_FILEPATH);
158 strcat(bp, coreName);
162 if ((code = stat(bp, &tstat)) == 0) {
164 if ((lastAnyExit - tstat.st_ctime) > 300) /* > 5 mins old */
170 (void)sprintf(bufp, "There is %score dump left %sfor this server\n",
171 (core ? (c ? "a recent " : "an 'old' ") : "no "),
173 bufp += strlen(bufp);
175 (void)sprintf(bufp, "Last Exit code %d\n", lastExit);
176 bufp += strlen(bufp);
177 (void)sprintf(bufp, "Last Signal number %d\n", lastSignal);
178 bufp += strlen(bufp);
181 strcpy(bp, "PROCESS STARTED");
182 else if (pflags == 2)
183 strcpy(bp, "PROCESS EXITED");
185 strcpy(bp, "UNKNOWN");
186 (void)sprintf(bufp, "Process state %d (%s)\n", pflags, bp);
187 bufp += strlen(bufp);
188 timeStamp = ctime(&rsTime);
190 (void)sprintf(bufp, "\nNumber of restarts since %s is %d\n", timeStamp,
192 bufp += strlen(bufp);
194 timeStamp = ctime(&procStartTime);
197 "Number of process restarts since the process started %s is %d\n",
198 timeStamp, procStarts);
200 bufp += strlen(bufp);
202 timeStamp = ctime(&lastAnyExit);
204 (void)sprintf(bufp, "Last time process exited for any reason: %s\n",
207 bufp += strlen(bufp);
209 timeStamp = ctime(&lastErrorExit);
211 (void)sprintf(bufp, "Last time process exited unexpectedly: %s\n",
214 bufp += strlen(bufp);
215 (void)sprintf(bufp, "Last exit return code %d\n", errorCode);
216 bufp += strlen(bufp);
217 (void)sprintf(bufp, "Last process terminating signal %d\n", errorSignal);
218 bufp += strlen(bufp);
220 if (strcmp(lastErrorName, "(null)"))
224 "Short name of process that failed last in this bnode is: %s\n",
226 bufp += strlen(bufp);
229 (void)sprintf(bufp, "The server is now %srunning\n",
230 (goal ? "" : "not "));
231 bufp += strlen(bufp);
232 len = (int)(bufp - bufp1);
233 if (write(fd, bufp1, len) < 0) {
241 sprintf(bufp1, "%s %s -s TESTING < %s", SENDMAIL, RECIPIENT, buf);
242 code = system(bufp1);