]>
Commit | Line | Data |
---|---|---|
96d806a4 | 1 | /* $Header$ |
2 | * | |
3 | * Log and send a zephyrgram about any critical errors. | |
4 | */ | |
5 | ||
6 | #include <stdio.h> | |
7 | #include <sys/file.h> | |
8 | #include <zephyr/zephyr.h> | |
9 | ||
10 | ||
11 | /* log file for critical events that require human intervention */ | |
12 | #define CRITERRLOG "/u1/sms/critical.log" | |
13 | ||
14 | /* mode to create the file with */ | |
15 | #define LOGFILEMODE 0644 | |
16 | ||
17 | ||
18 | void critical_alert(instance, msg, args) | |
19 | char *instance; /* Instance for zephyr gram */ | |
20 | char *msg; /* printf format message */ | |
21 | /* args = arguements, printf style */ | |
22 | /* This routine sends a class SMS zephyrgram of specified instance | |
23 | and logs to a special logfile the message passed to it via msg | |
24 | and args in printf format. */ | |
25 | /* Note: The part of this code that process the variable arguements | |
26 | was stolen from sprintf(). */ | |
27 | { | |
28 | FILE _bufstr; /* For _doprnt() */ | |
29 | int crit; /* File descriptor for critical log file */ | |
30 | char buf[BUFSIZ]; /* Holds the formatted message */ | |
31 | ||
32 | /* Put the fully formatted message into buf */ | |
33 | _bufstr._flag = _IOWRT + _IOSTRG; | |
34 | _bufstr._ptr = buf; | |
35 | _bufstr._cnt = BUFSIZ; | |
36 | _doprnt(msg, &args, &_bufstr); | |
37 | putc('\0', &_bufstr); | |
38 | ||
39 | /* Send zephyr notice */ | |
40 | send_zgram(instance, buf); | |
41 | ||
42 | /* Log message to critical file */ | |
43 | if ((crit = open(CRITERRLOG, | |
44 | O_WRONLY | O_APPEND | O_CREAT, LOGFILEMODE)) >= 0) | |
45 | { | |
46 | write(crit,buf,strlen(buf)); | |
47 | close(crit); | |
48 | } | |
49 | } | |
50 | ||
51 | ||
52 | ||
53 | /* Sends a zephyrgram of class "SMS", instance as a parameter. Ignores | |
54 | * errors while sending message. | |
55 | */ | |
56 | ||
57 | send_zgram(inst, msg) | |
58 | char *inst; | |
59 | char *msg; | |
60 | { | |
61 | ZNotice_t znotice; | |
62 | ||
63 | bzero (&znotice, sizeof (znotice)); | |
64 | znotice.z_kind = UNSAFE; | |
65 | znotice.z_class = "SMS"; | |
66 | znotice.z_class_inst = inst; | |
67 | znotice.z_default_format = "SMS $instance:\n $message\n"; | |
68 | (void) ZInitialize (); | |
69 | znotice.z_message = msg; | |
70 | znotice.z_message_len = strlen(msg) + 1; | |
71 | znotice.z_opcode = ""; | |
72 | znotice.z_recipient = ""; | |
73 | ZSendNotice(&znotice, ZNOAUTH); | |
74 | } |