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>
16 #include <afs/afsutil.h>
19 * XXX CHANGE the following depedent stuff XXX
21 #define SENDMAIL "/afs/cellname/fs/dev/localtools/dest/bin/rcs-sendmail"
23 * Replace it with a bboard (i.e. transarc.bosserver.auto-reports)
25 #define RECIPIENT "foo@cellname"
27 #include "AFS_component_version_number.c"
35 char buf[BUFSIZ], *bufp, *bufp1, *typep, *cmd, *bp;
36 afs_int32 code, c, fd, id, pflags = -1, len, core = 0, lastE = 0;
37 char comLine[60], coreName[40], name[40], lastErrorName[50];
38 afs_int32 pid = -1, lastExit = -1, lastSignal = -1, rsCount = -1;
39 afs_int32 procStarts = -1;
40 afs_int32 errorCode = -1, errorSignal = -1, goal = -1;
41 time_t procStartTime = -1, rsTime = -1, lastAnyExit = -1, lastErrorExit = -1;
44 typep = (char *)malloc(50);
45 cmd = (char *)malloc(50);
46 bufp = bufp1 = (char *)malloc(1000);
47 while (fgets(buf, sizeof(buf), fin)) {
48 code = sscanf(buf, "%s %s\n", typep, cmd);
52 if (!strcmp(typep, "BEGIN") && !strcmp(cmd, "bnode_proc")) {
53 while (fgets(buf, sizeof(buf), fin)) {
54 code = sscanf(buf, "%s %s\n", typep, cmd);
56 printf("**bnode_proc**: typed=%s, cmd=%s\n", typep, cmd);
59 if (!strcmp(typep, "comLine:"))
61 else if (!strcmp(typep, "coreName:"))
62 strcpy(coreName, cmd);
63 else if (!strcmp(typep, "pid:"))
66 else if (!strcmp(typep, "lastExit:"))
68 else if (!strcmp(typep, "lastSignal:"))
69 lastSignal = atoi(cmd);
71 else if (!strcmp(typep, "flags:"))
73 else if (!strcmp(typep, "END")) {
77 ("Unexpected token %s in the bnode_proc (should be END)\n",
82 } else if (!strcmp(typep, "BEGIN") && !strcmp(cmd, "bnode")) {
83 while (fgets(buf, sizeof(buf), fin)) {
84 code = sscanf(buf, "%s %s\n", typep, cmd);
86 printf("**bnode**: typed=%s, cmd=%s\n", typep, cmd);
89 if (!strcmp(typep, "name:"))
91 else if (!strcmp(typep, "rsTime:"))
93 else if (!strcmp(typep, "rsCount:"))
95 else if (!strcmp(typep, "procStartTime:"))
96 procStartTime = atoi(cmd);
97 else if (!strcmp(typep, "procStarts:"))
98 procStarts = atoi(cmd);
99 else if (!strcmp(typep, "lastAnyExit:"))
100 lastAnyExit = atoi(cmd);
101 else if (!strcmp(typep, "lastErrorExit:"))
102 lastErrorExit = atoi(cmd);
103 else if (!strcmp(typep, "errorCode:"))
104 errorCode = atoi(cmd);
105 else if (!strcmp(typep, "errorSignal:"))
106 errorSignal = atoi(cmd);
108 else if (!strcmp(typep, "lastErrorName:"))
109 strcpy(lastErrorName, cmd);
111 else if (!strcmp(typep, "goal:"))
113 else if (!strcmp(typep, "END")) {
117 ("Unexpected token %s in the bnode (should be END)\n",
123 printf("Unexpected token %s (should be BEGIN)\n", typep);
128 * Now make up the text for the post
130 sprintf(buf, "/tmp/snote.%d", getpid());
131 fd = open(buf, O_RDWR | O_CREAT | O_TRUNC, 0600);
134 printf("Unable to create temp file, %s\n", buf);
137 (void)sprintf(bufp, "Subject: Bosserver's automatic notification\n\n");
138 bufp += strlen(bufp);
140 "AUTOMATIC NOTIFICATION EVENT FOR AFS SERVER INSTANCE %s\n\n",
142 bufp += strlen(bufp);
143 (void)sprintf(bufp, "Server Process id was: %d\n", pid);
144 bufp += strlen(bufp);
145 (void)sprintf(bufp, "Server command line: %s\n", comLine);
146 bufp += strlen(bufp);
147 if (strcmp(coreName, "(null)"))
150 strcpy(bp, AFSDIR_SERVER_CORELOG_FILEPATH);
152 strcat(bp, coreName);
156 if ((code = stat(bp, &tstat)) == 0) {
158 if ((lastAnyExit - tstat.st_ctime) > 300) /* > 5 mins old */
164 (void)sprintf(bufp, "There is %score dump left %sfor this server\n",
165 (core ? (c ? "a recent " : "an 'old' ") : "no "),
167 bufp += strlen(bufp);
169 (void)sprintf(bufp, "Last Exit code %d\n", lastExit);
170 bufp += strlen(bufp);
171 (void)sprintf(bufp, "Last Signal number %d\n", lastSignal);
172 bufp += strlen(bufp);
175 strcpy(bp, "PROCESS STARTED");
176 else if (pflags == 2)
177 strcpy(bp, "PROCESS EXITED");
179 strcpy(bp, "UNKNOWN");
180 (void)sprintf(bufp, "Process state %d (%s)\n", pflags, bp);
181 bufp += strlen(bufp);
182 timeStamp = ctime(&rsTime);
184 (void)sprintf(bufp, "\nNumber of restarts since %s is %d\n", timeStamp,
186 bufp += strlen(bufp);
188 timeStamp = ctime(&procStartTime);
191 "Number of process restarts since the process started %s is %d\n",
192 timeStamp, procStarts);
194 bufp += strlen(bufp);
196 timeStamp = ctime(&lastAnyExit);
198 (void)sprintf(bufp, "Last time process exited for any reason: %s\n",
201 bufp += strlen(bufp);
203 timeStamp = ctime(&lastErrorExit);
205 (void)sprintf(bufp, "Last time process exited unexpectedly: %s\n",
208 bufp += strlen(bufp);
209 (void)sprintf(bufp, "Last exit return code %d\n", errorCode);
210 bufp += strlen(bufp);
211 (void)sprintf(bufp, "Last process terminating signal %d\n", errorSignal);
212 bufp += strlen(bufp);
214 if (strcmp(lastErrorName, "(null)"))
218 "Short name of process that failed last in this bnode is: %s\n",
220 bufp += strlen(bufp);
223 (void)sprintf(bufp, "The server is now %srunning\n",
224 (goal ? "" : "not "));
225 bufp += strlen(bufp);
226 len = (int)(bufp - bufp1);
227 if (write(fd, bufp1, len) < 0) {
235 sprintf(bufp1, "%s %s -s TESTING < %s", SENDMAIL, RECIPIENT, buf);
236 code = system(bufp1);