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
20 void critical_alert(instance, msg, args)
21 char *instance; /* Instance for zephyr gram */
22 char *msg; /* printf format message */
23 /* args = arguements, printf style */
24 /* This routine sends a class SMS zephyrgram of specified instance
25 and logs to a special logfile the message passed to it via msg
26 and args in printf format. *** It expects the global variable
27 whoami to be defined and contain the name of the calling program. */
28 /* Note: The part of this code that process the variable arguements
29 was stolen from sprintf(). */
31 FILE _bufstr; /* For _doprnt() */
32 FILE *crit; /* FILE for critical log file */
33 char buf[BUFSIZ]; /* Holds the formatted message */
35 /* Put the fully formatted message into buf */
36 _bufstr._flag = _IOWRT + _IOSTRG;
38 _bufstr._cnt = BUFSIZ;
39 _doprnt(msg, &args, &_bufstr);
42 /* Send zephyr notice */
43 send_zgram(instance, buf);
45 /* Log message to critical file */
46 if ((crit = fopen(CRITERRLOG, "a")) != (FILE *)NULL)
52 time_s = ctime(&t) + 4;
53 time_s[strlen(time_s)-6] = '\0';
55 fprintf(crit, "%s <%d> %s\n", time_s, getpid(), buf);
59 com_err(whoami, 0, buf);
64 /* Sends a zephyrgram of class "SMS", instance as a parameter. Ignores
65 * errors while sending message.
74 bzero (&znotice, sizeof (znotice));
75 znotice.z_kind = UNSAFE;
76 znotice.z_class = "SMS";
77 znotice.z_class_inst = inst;
78 znotice.z_default_format = "SMS $instance:\n $message\n";
79 (void) ZInitialize ();
80 znotice.z_message = msg;
81 znotice.z_message_len = strlen(msg) + 1;
82 znotice.z_opcode = "";
83 znotice.z_recipient = "";
84 ZSendNotice(&znotice, ZNOAUTH);