3 * Log and send a zephyrgram about any critical errors.
8 #include <zephyr/zephyr.h>
11 /* log file for critical events that require human intervention */
12 #define CRITERRLOG "/u1/sms/critical.log"
14 /* mode to create the file with */
15 #define LOGFILEMODE 0644
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. *** It expects the global variable
25 whoami to be defined and contain the name of the calling program. */
26 /* Note: The part of this code that process the variable arguements
27 was stolen from sprintf(). */
29 FILE _bufstr; /* For _doprnt() */
30 FILE *crit; /* FILE for critical log file */
31 char buf[BUFSIZ]; /* Holds the formatted message */
33 /* Put the fully formatted message into buf */
34 _bufstr._flag = _IOWRT + _IOSTRG;
36 _bufstr._cnt = BUFSIZ;
37 _doprnt(msg, &args, &_bufstr);
40 /* Send zephyr notice */
41 send_zgram(instance, buf);
43 /* Log message to critical file */
44 if ((crit = fopen(CRITERRLOG, "a")) != (FILE *)NULL)
50 time_s = ctime(&t) + 4;
51 time_s[strlen(time_s)-6] = '\0';
53 fprintf(crit, "%s <%d> %s\n", time_s, getpid(), buf);
57 com_err(whoami, 0, buf);
62 /* Sends a zephyrgram of class "SMS", instance as a parameter. Ignores
63 * errors while sending message.
72 bzero (&znotice, sizeof (znotice));
73 znotice.z_kind = UNSAFE;
74 znotice.z_class = "SMS";
75 znotice.z_class_inst = inst;
76 znotice.z_default_format = "SMS $instance:\n $message\n";
77 (void) ZInitialize ();
78 znotice.z_message = msg;
79 znotice.z_message_len = strlen(msg) + 1;
80 znotice.z_opcode = "";
81 znotice.z_recipient = "";
82 ZSendNotice(&znotice, ZNOAUTH);