]> andersk Git - moira.git/blobdiff - lib/critical.c
remove dependancy on resolver internals
[moira.git] / lib / critical.c
index b4f63c2776dc7891267fe03ec0180a60e0467c6a..c0af33bf1f294564c6e836c7e1887b2226ecf4ee 100644 (file)
@@ -9,40 +9,42 @@
 
 #include <mit-copyright.h>
 #include <stdio.h>
+#include <sys/types.h>
 #include <sys/file.h>
+#include <moira_site.h>
+#ifdef ZEPHYR
 #include <zephyr/zephyr.h>
+#endif
+#ifdef SYSLOG
+#include <syslog.h>
+#endif
 
 
-/* log file for critical events that require human intervention */
-#define CRITERRLOG     "/u1/sms/critical.log"
-
 /* mode to create the file with */
 #define LOGFILEMODE    0644
 
 extern char *whoami;
 
 
-void critical_alert(instance, msg, args)
+/* This routine sends a class MOIRA zephyrgram of specified instance
+ * and logs to a special logfile the message passed to it via msg
+ * and args in printf format.  *** It expects the global variable
+ * whoami to be defined and contain the name of the calling program.
+ * It's a kludge that it takes a max of 8 arguments in a way that
+ * isn't necessarily portable, but varargs doesn't work here and we
+ * don't have vsprintf().
+ */
+
+void critical_alert(instance, msg, arg1, arg2, arg3, arg4,
+                   arg5, arg6, arg7, arg8)
   char *instance;              /* Instance for zephyr gram */
   char *msg;                   /* printf format message */
-                               /* args = arguements, printf style */
-  /* This routine sends a class SMS zephyrgram of specified instance
-     and logs to a special logfile the message passed to it via msg
-     and args in printf format.  *** It expects the global variable
-     whoami to be defined and contain the name of the calling program. */
-  /* Note: The part of this code that process the variable arguements
-     was stolen from sprintf(). */
+  char *arg1, *arg2, *arg3, *arg4, *arg5, *arg6, *arg7, *arg8;
 {
-    FILE _bufstr;              /* For _doprnt() */
     FILE *crit;                        /* FILE for critical log file */
     char buf[BUFSIZ];          /* Holds the formatted message */
 
-    /* Put the fully formatted message into buf */
-    _bufstr._flag = _IOWRT + _IOSTRG;
-    _bufstr._ptr = buf;
-    _bufstr._cnt = BUFSIZ;
-    _doprnt(msg, &args, &_bufstr);
-    putc('\0', &_bufstr);
+    sprintf(buf, msg, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
 
     /* Send zephyr notice */
     send_zgram(instance, buf);
@@ -50,7 +52,7 @@ void critical_alert(instance, msg, args)
     /* Log message to critical file */
     if ((crit = fopen(CRITERRLOG, "a")) != (FILE *)NULL) 
     {
-       long t;
+       long t, time();
        char  *time_s;
 
        time(&t);
@@ -66,7 +68,7 @@ void critical_alert(instance, msg, args)
 
 
 
-/* Sends a zephyrgram of class "SMS", instance as a parameter.  Ignores
+/* Sends a zephyrgram of class "MOIRA", instance as a parameter.  Ignores
  * errors while sending message.
  */
 
@@ -74,17 +76,26 @@ send_zgram(inst, msg)
 char *inst;
 char *msg;
 {
+#ifdef ZEPHYR
     ZNotice_t znotice;
 
     bzero (&znotice, sizeof (znotice));
     znotice.z_kind = UNSAFE;
-    znotice.z_class = "SMS";
+    znotice.z_class = "MOIRA";
     znotice.z_class_inst = inst;
-    znotice.z_default_format = "SMS $instance:\n $message\n";
+    znotice.z_default_format = "MOIRA $instance on $fromhost:\n $message\n";
     (void) ZInitialize ();
     znotice.z_message = msg;
     znotice.z_message_len = strlen(msg) + 1;
     znotice.z_opcode = "";
     znotice.z_recipient = "";
     ZSendNotice(&znotice, ZNOAUTH);
+#endif
+#ifdef SYSLOG
+    {
+       char buf[512];
+       sprintf(buf, "MOIRA: %s %s", inst, msg);
+       syslog(LOG_ERR, buf);
+    }
+#endif
 }
This page took 0.066683 seconds and 4 git commands to generate.