]> andersk Git - moira.git/blame - lib/critical.c
fixed a syntax error
[moira.git] / lib / critical.c
CommitLineData
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
18void 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() */
3f6b08ec 29 FILE *crit; /* FILE for critical log file */
96d806a4 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 */
3f6b08ec 43 if ((crit = fopen(CRITERRLOG, "a")) != (FILE *)NULL)
96d806a4 44 {
3f6b08ec 45 long t;
46 char *time_s;
47
48 time(&t);
49 time_s = ctime(&t) + 4;
50 time_s[strlen(time_s)-6] = '\0';
51
52 fprintf(crit, "%s <%d> %s\n", time_s, getpid(), buf);
53 fclose(crit);
96d806a4 54 }
55}
56
57
58
59/* Sends a zephyrgram of class "SMS", instance as a parameter. Ignores
60 * errors while sending message.
61 */
62
63send_zgram(inst, msg)
64char *inst;
65char *msg;
66{
67 ZNotice_t znotice;
68
69 bzero (&znotice, sizeof (znotice));
70 znotice.z_kind = UNSAFE;
71 znotice.z_class = "SMS";
72 znotice.z_class_inst = inst;
73 znotice.z_default_format = "SMS $instance:\n $message\n";
74 (void) ZInitialize ();
75 znotice.z_message = msg;
76 znotice.z_message_len = strlen(msg) + 1;
77 znotice.z_opcode = "";
78 znotice.z_recipient = "";
79 ZSendNotice(&znotice, ZNOAUTH);
80}
This page took 0.05456 seconds and 5 git commands to generate.