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 register 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, rsTime = -1, rsCount =
46 afs_int32 procStartTime = -1, procStarts = -1;
47 afs_int32 lastAnyExit = -1, lastErrorExit = -1, errorCode =
48 -1, errorSignal = -1, goal = -1;
51 typep = (char *)malloc(50);
52 cmd = (char *)malloc(50);
53 bufp = bufp1 = (char *)malloc(1000);
54 while (fgets(buf, sizeof(buf), fin)) {
55 code = sscanf(buf, "%s %s\n", typep, cmd);
59 if (!strcmp(typep, "BEGIN") && !strcmp(cmd, "bnode_proc")) {
60 while (fgets(buf, sizeof(buf), fin)) {
61 code = sscanf(buf, "%s %s\n", typep, cmd);
63 printf("**bnode_proc**: typed=%s, cmd=%s\n", typep, cmd);
66 if (!strcmp(typep, "comLine:"))
68 else if (!strcmp(typep, "coreName:"))
69 strcpy(coreName, cmd);
70 else if (!strcmp(typep, "pid:"))
73 else if (!strcmp(typep, "lastExit:"))
75 else if (!strcmp(typep, "lastSignal:"))
76 lastSignal = atoi(cmd);
78 else if (!strcmp(typep, "flags:"))
80 else if (!strcmp(typep, "END")) {
84 ("Unexpected token %s in the bnode_proc (should be END)\n",
89 } else if (!strcmp(typep, "BEGIN") && !strcmp(cmd, "bnode")) {
90 while (fgets(buf, sizeof(buf), fin)) {
91 code = sscanf(buf, "%s %s\n", typep, cmd);
93 printf("**bnode**: typed=%s, cmd=%s\n", typep, cmd);
96 if (!strcmp(typep, "name:"))
98 else if (!strcmp(typep, "rsTime:"))
100 else if (!strcmp(typep, "rsCount:"))
102 else if (!strcmp(typep, "procStartTime:"))
103 procStartTime = atoi(cmd);
104 else if (!strcmp(typep, "procStarts:"))
105 procStarts = atoi(cmd);
106 else if (!strcmp(typep, "lastAnyExit:"))
107 lastAnyExit = atoi(cmd);
108 else if (!strcmp(typep, "lastErrorExit:"))
109 lastErrorExit = atoi(cmd);
110 else if (!strcmp(typep, "errorCode:"))
111 errorCode = atoi(cmd);
112 else if (!strcmp(typep, "errorSignal:"))
113 errorSignal = atoi(cmd);
115 else if (!strcmp(typep, "lastErrorName:"))
116 strcpy(lastErrorName, cmd);
118 else if (!strcmp(typep, "goal:"))
120 else if (!strcmp(typep, "END")) {
124 ("Unexpected token %s in the bnode (should be END)\n",
130 printf("Unexpected token %s (should be BEGIN)\n", typep);
135 * Now make up the text for the post
137 sprintf(buf, "/tmp/snote.%d", getpid());
138 fd = open(buf, O_RDWR | O_CREAT | O_TRUNC, 0600);
141 printf("Unable to create temp file, %s\n", buf);
144 (void)sprintf(bufp, "Subject: Bosserver's automatic notification\n\n");
145 bufp += strlen(bufp);
147 "AUTOMATIC NOTIFICATION EVENT FOR AFS SERVER INSTANCE %s\n\n",
149 bufp += strlen(bufp);
150 (void)sprintf(bufp, "Server Process id was: %d\n", pid);
151 bufp += strlen(bufp);
152 (void)sprintf(bufp, "Server command line: %s\n", comLine);
153 bufp += strlen(bufp);
154 if (strcmp(coreName, "(null)"))
157 strcpy(bp, AFSDIR_SERVER_CORELOG_FILEPATH);
159 strcat(bp, coreName);
163 if ((code = stat(bp, &tstat)) == 0) {
165 if ((lastAnyExit - tstat.st_ctime) > 300) /* > 5 mins old */
171 (void)sprintf(bufp, "There is %score dump left %sfor this server\n",
172 (core ? (c ? "a recent " : "an 'old' ") : "no "),
174 bufp += strlen(bufp);
176 (void)sprintf(bufp, "Last Exit code %d\n", lastExit);
177 bufp += strlen(bufp);
178 (void)sprintf(bufp, "Last Signal number %d\n", lastSignal);
179 bufp += strlen(bufp);
182 strcpy(bp, "PROCESS STARTED");
183 else if (pflags == 2)
184 strcpy(bp, "PROCESS EXITED");
186 strcpy(bp, "UNKNOWN");
187 (void)sprintf(bufp, "Process state %d (%s)\n", pflags, bp);
188 bufp += strlen(bufp);
189 timeStamp = ctime(&rsTime);
191 (void)sprintf(bufp, "\nNumber of restarts since %s is %d\n", timeStamp,
193 bufp += strlen(bufp);
195 timeStamp = ctime(&procStartTime);
198 "Number of process restarts since the process started %s is %d\n",
199 timeStamp, procStarts);
201 bufp += strlen(bufp);
203 timeStamp = ctime(&lastAnyExit);
205 (void)sprintf(bufp, "Last time process exited for any reason: %s\n",
208 bufp += strlen(bufp);
210 timeStamp = ctime(&lastErrorExit);
212 (void)sprintf(bufp, "Last time process exited unexpectedly: %s\n",
215 bufp += strlen(bufp);
216 (void)sprintf(bufp, "Last exit return code %d\n", errorCode);
217 bufp += strlen(bufp);
218 (void)sprintf(bufp, "Last process terminating signal %d\n", errorSignal);
219 bufp += strlen(bufp);
221 if (strcmp(lastErrorName, "(null)"))
225 "Short name of process that failed last in this bnode is: %s\n",
227 bufp += strlen(bufp);
230 (void)sprintf(bufp, "The server is now %srunning\n",
231 (goal ? "" : "not "));
232 bufp += strlen(bufp);
233 len = (int)(bufp - bufp1);
234 if (write(fd, bufp1, len) < 0) {
242 sprintf(bufp1, "%s %s -s TESTING < %s", SENDMAIL, RECIPIENT, buf);
243 code = system(bufp1);