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 <afs/param.h>
11 #include <afsconfig.h>
16 #include <sys/types.h>
21 #include <netinet/in.h>
23 #include <afs/afsutil.h>
26 * XXX CHANGE the following depedent stuff XXX
28 #define SENDMAIL "/afs/cellname/fs/dev/localtools/dest/bin/rcs-sendmail"
30 * Replace it with a bboard (i.e. transarc.bosserver.auto-reports)
32 #define RECIPIENT "foo@cellname"
34 #include "AFS_component_version_number.c"
42 char buf[BUFSIZ], *bufp, *bufp1, *typep, *cmd, *bp;
43 register afs_int32 code, c, fd, id, pflags=-1, len, core=0, lastE=0;
44 char comLine[60], coreName[40], name[40], lastErrorName[50];
45 afs_int32 pid=-1, lastExit=-1, lastSignal=-1, rsTime=-1, rsCount=-1;
46 afs_int32 procStartTime=-1, procStarts=-1;
47 afs_int32 lastAnyExit=-1, lastErrorExit=-1, errorCode=-1, errorSignal=-1, goal=-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")) {
82 printf("Unexpected token %s in the bnode_proc (should be END)\n", typep);
86 } else if (!strcmp(typep, "BEGIN") && !strcmp(cmd, "bnode")) {
87 while (fgets(buf, sizeof(buf), fin)) {
88 code = sscanf(buf, "%s %s\n", typep, cmd);
90 printf("**bnode**: typed=%s, cmd=%s\n", typep, cmd);
93 if (!strcmp(typep, "name:"))
95 else if (!strcmp(typep, "rsTime:"))
97 else if (!strcmp(typep, "rsCount:"))
99 else if (!strcmp(typep, "procStartTime:"))
100 procStartTime = atoi(cmd);
101 else if (!strcmp(typep, "procStarts:"))
102 procStarts = atoi(cmd);
103 else if (!strcmp(typep, "lastAnyExit:"))
104 lastAnyExit = atoi(cmd);
105 else if (!strcmp(typep, "lastErrorExit:"))
106 lastErrorExit = atoi(cmd);
107 else if (!strcmp(typep, "errorCode:"))
108 errorCode = atoi(cmd);
109 else if (!strcmp(typep, "errorSignal:"))
110 errorSignal = atoi(cmd);
112 else if (!strcmp(typep, "lastErrorName:"))
113 strcpy(lastErrorName, cmd);
115 else if (!strcmp(typep, "goal:"))
117 else if (!strcmp(typep, "END")) {
120 printf("Unexpected token %s in the bnode (should be END)\n", typep);
125 printf("Unexpected token %s (should be BEGIN)\n", typep);
130 * Now make up the text for the post
132 sprintf(buf, "/tmp/snote.%d", getpid());
133 fd = open(buf, O_RDWR|O_CREAT|O_TRUNC, 0600);
136 printf("Unable to create temp file, %s\n", buf);
139 (void) sprintf(bufp, "Subject: Bosserver's automatic notification\n\n");
140 bufp += strlen(bufp);
141 (void) sprintf(bufp, "AUTOMATIC NOTIFICATION EVENT FOR AFS SERVER INSTANCE %s\n\n", name);
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)")) core = 1;
149 strcpy(bp, AFSDIR_SERVER_CORELOG_FILEPATH);
151 strcat(bp, coreName);
155 if ((code = stat(bp, &tstat)) == 0) {
157 if ((lastAnyExit - tstat.st_ctime) > 300) /* > 5 mins old */
163 (void) sprintf(bufp, "There is %score dump left %sfor this server\n",
164 (core?(c?"a recent ":"an 'old' "):"no "), (core?bp:""));
165 bufp += strlen(bufp);
167 (void) sprintf(bufp, "Last Exit code %d\n", lastExit);
168 bufp += strlen(bufp);
169 (void) sprintf(bufp, "Last Signal number %d\n", lastSignal);
170 bufp += strlen(bufp);
173 strcpy(bp, "PROCESS STARTED");
174 else if (pflags == 2)
175 strcpy(bp, "PROCESS EXITED");
177 strcpy(bp, "UNKNOWN");
178 (void) sprintf(bufp, "Process state %d (%s)\n", pflags, bp);
179 bufp += strlen(bufp);
180 timeStamp = ctime(&rsTime);
182 (void) sprintf(bufp, "\nNumber of restarts since %s is %d\n", timeStamp, rsCount);
183 bufp += strlen(bufp);
185 timeStamp = ctime(&procStartTime);
187 (void) sprintf(bufp, "Number of process restarts since the process started %s is %d\n", timeStamp, procStarts);
189 bufp += strlen(bufp);
191 timeStamp = ctime(&lastAnyExit);
193 (void) sprintf(bufp, "Last time process exited for any reason: %s\n", timeStamp);
195 bufp += strlen(bufp);
197 timeStamp = ctime(&lastErrorExit);
199 (void) sprintf(bufp, "Last time process exited unexpectedly: %s\n", timeStamp);
201 bufp += strlen(bufp);
202 (void) sprintf(bufp, "Last exit return code %d\n", errorCode);
203 bufp += strlen(bufp);
204 (void) sprintf(bufp, "Last process terminating signal %d\n", errorSignal);
205 bufp += strlen(bufp);
207 if (strcmp(lastErrorName, "(null)")) lastE = 1;
209 (void) sprintf(bufp, "Short name of process that failed last in this bnode is: %s\n", lastErrorName);
210 bufp += strlen(bufp);
213 (void) sprintf(bufp, "The server is now %srunning\n", (goal?"":"not "));
214 bufp += strlen(bufp);
215 len =(int)(bufp-bufp1);
216 if (write(fd, bufp1, len) < 0) {
224 sprintf(bufp1, "%s %s -s TESTING < %s", SENDMAIL, RECIPIENT, buf);
225 code = system(bufp1);