home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / ultrix / 6760 < prev    next >
Encoding:
Text File  |  1992-09-08  |  12.1 KB  |  356 lines

  1. Newsgroups: comp.unix.ultrix
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!convex!seas.smu.edu!doug
  3. From: doug@seas.smu.edu (Doug Davis)
  4. Subject: /dev/errlog (aka elcsd errors) into syslog.. (source)
  5. Message-ID: <1992Sep8.152630.1114@seas.smu.edu>
  6. Summary: putting elcsd into the normal syslog
  7. Keywords: elcsd errlog uerf
  8. Sender: news@seas.smu.edu (USENET News System)
  9. Nntp-Posting-Host: turbo_f.seas.smu.edu
  10. Organization: School of Engineering and Applied Science
  11. Date: Tue, 8 Sep 1992 15:26:30 GMT
  12. Lines: 342
  13.  
  14.  
  15.  
  16. /*
  17. ** This program monitors the /dev/errlog device and sends the information
  18. ** found there to the syslog system..  This is useful to all of 
  19. ** us that had existing systems where all the machines logged their
  20. ** syslog stuff to a single machine (or program) which people then
  21. ** monitored.  
  22. **
  23. ** NOTE: Dec recommends that you use the UERF/ELI system. Which is 
  24. ** probably better, if not, at least more complete than this.
  25. **
  26. ** HOWEVER! There is no way (that I have found) to monitor UERF over
  27. ** a bunch of machines in real time at once.   Yes a program COULD
  28. ** be written to sit on all the elbuffer files that could be written
  29. ** from various machines on one machines but I dislike monitoring of
  30. ** non-ascii files its just not the unix(tm) way :-)
  31. **
  32. ** Also, to use this system effectively, I.e. with your sun's and 
  33. ** and everything else that SUPPORTS syslog you need the current version
  34. ** of /etc/syslog which can be found on the BSD tape.   An executable
  35. ** for DECstations is sitting in seas.smu.edu's ~ftp/pub/DEC directory
  36. ** along with a sample syslog.conf.  
  37. **
  38. ** Of course theres always SNMP (ack, pfft!)
  39. **
  40. ** BUGS: 
  41. **  This program needs a lot of work to make it truly complete, currently
  42. **  it recognizes only a tiny bit of the errors that your ultrix machine
  43. **  is capable of producing.
  44. **
  45. ** THANKS TO: DEC support, even though /dev/errlog isn't DOCUMENTED in
  46. ** the ultrix man pages they were able to locate the correct ioctls 
  47. ** to interface with the errlog device driver..
  48. **
  49. ** AUTHOR: doug davis  (doug@seas.smu.edu)
  50. **
  51. ** WARRANTY: none whatsoever
  52. **
  53. ** TODO:
  54. **     o) Add more error interpretations
  55. **    o) Add a "tunable" severity clause for syslog(xxxxx, ..)
  56. */
  57.  
  58. #include <sys/types.h>
  59. #include <sys/param.h>
  60. #include <sys/time.h>
  61. #include <sys/socket.h>
  62. #include <sys/un.h>
  63. #include <stdio.h>
  64. #include <sys/errlog.h>
  65. #include <fcntl.h>
  66. #include <sys/ioctl.h>
  67. #include <elcsd.h>
  68. #include <syslog.h>
  69.  
  70. #define NAME "/dev/errlog"
  71. extern char *ctime(), *subclass(), *devices();
  72.  
  73. main()
  74. {
  75.     int errlog, length;
  76.     int i;
  77.     struct el_rec el_rec;
  78.     struct elparam elparam;
  79.     fd_set readfds, writefds, exceptfds;
  80.     int nf, cc;
  81.  
  82.     /* deattach from the calling terminal */
  83.     if (fork())
  84.         exit(0);
  85.     for (i = 0; i < 10; i++)
  86.                (void) close(i);
  87.     (void) open("/", 0);
  88.     (void) dup2(0, 1);
  89.     (void) dup2(0, 2);
  90.     if((i = open("/dev/tty", O_RDWR)) >= 0) {
  91.         (void) ioctl(i, (int) TIOCNOTTY, (char *)0);
  92.         (void) close(i);
  93.     }
  94.     
  95.  
  96.     /* open the syslog errlogging system */
  97.     if(openlog("UERF", 0) == -1) {
  98.         perror("openlog");
  99.         exit(1);
  100.     }
  101.     syslog(LOG_INFO, "syslog error monitor restart");
  102.  
  103.     if((errlog = open(NAME, O_RDWR)) < 0) {
  104.         if (errlog < 0) {
  105.             perror("opening errlog device");
  106.             exit(1);
  107.         }
  108.     }
  109.  
  110.     /* make sure they are clean.. */
  111.     FD_ZERO(&readfds);
  112.     FD_ZERO(&writefds);
  113.     FD_ZERO(&exceptfds);
  114.  
  115.     /*
  116.     ** This inits the kernel's DCB with the PID of this
  117.     ** process.  One wonders about the need for this since 
  118.     ** any system call should come complete with the u and proc pages
  119.     ** from the calling user program..
  120.     */
  121.     elparam.pid = getpid();
  122.     ioctl(errlog, ELSETPID, &elparam);
  123.  
  124.     for(;;) {
  125.         FD_SET (errlog, &readfds);
  126.         /* Something to read? */
  127.         nf = select(20, &readfds, &writefds, &exceptfds, (struct timeval *) NULL);
  128.  
  129.         /* read data from the device */
  130.         if((cc=read(errlog, &el_rec, sizeof(struct el_rec))) < 0) {
  131.             panic("read from errlog");
  132.         }
  133.         
  134.         /* output it.. */
  135.         printerr(el_rec.elsubid.subid_class, &el_rec);
  136.  
  137.         /*
  138.         ** This advances the pointer for the "in core" errlog buffer by (int) *cc bytes.
  139.         */
  140.         ioctl(errlog, ELMOVPTR, (char *) &cc);
  141.     }
  142.     /* NOTREACHED */
  143.     close(errlog);
  144. }
  145. panic(s)
  146. char *s;
  147. {
  148.     syslog(LOG_ALERT, "errlogger panic: %s\n", s);
  149.     exit(-1);
  150. }
  151.  
  152. /*
  153. ** This prints in quasi human readable form ;-) the error message
  154. ** to the syslog system.   NOTE: There is only a TINY handful
  155. ** of the of errors supported.  If you want to add some more 
  156. ** feel free.   Look in /usr/include/sys/errlog.h  for the
  157. ** #defines and structures being used below..
  158. **
  159. ** And if you do add some more PLEASE send them back so I
  160. ** can incorporate the changes!!
  161. */
  162.  
  163. printerr(n, el_rec)
  164. u_short n;
  165. struct el_rec *el_rec;
  166. {
  167.     int i;
  168.     switch(n) {
  169.         case ELMSGT_TIM: { /* time stamp */
  170.             syslog(LOG_ALERT, "%d TIMS: new time %24.24s %s",
  171.                 el_rec->elrhdr.rhdr_seqnum,
  172.                 ctime(&el_rec->el_body.eltimchg.timchg_time.tv_sec),
  173.                 el_rec->el_body.eltimchg.timchg_version);
  174.         } break;
  175.  
  176.         case ELCT_MEM: { /* mem. crd/rds */
  177.             static char *memtype[] = { "crd", "rds", "cntrl", "wmask" } ;
  178.             syslog(LOG_ALERT, "%d MEMK: cntrl = %d  type = %s number = %d",
  179.                 el_rec->elrhdr.rhdr_seqnum,
  180.                 el_rec->el_body.elmem.elmemerr.cntl,
  181.                 memtype[el_rec->el_body.elmem.elmemerr.type],
  182.                 el_rec->el_body.elmem.elmemerr.numerr);
  183.         }; break;
  184.  
  185.         case ELCT_DCNTL: { /* device/controler errors */
  186.             syslog(LOG_ALERT, "%d DEVE: %s",
  187.                 el_rec->elrhdr.rhdr_seqnum,
  188.                 devices(el_rec));
  189.         }
  190.  
  191.         case ELMSGT_SU: {
  192.             syslog(LOG_ALERT, "%d STRT: %s",
  193.                 el_rec->elrhdr.rhdr_seqnum,
  194.                 el_rec->el_body.elmsg.msg_asc);
  195.         } break;
  196.         case ELMSGT_SD: {
  197.             syslog(LOG_ALERT, "%d STOP: %s",
  198.                 el_rec->elrhdr.rhdr_seqnum,
  199.                 el_rec->el_body.elmsg.msg_asc);
  200.         } break;
  201.         case ELMSGT_INFO: { /* ascii message */
  202.             syslog(LOG_ALERT, "%d INFO: %s",
  203.                 el_rec->elrhdr.rhdr_seqnum,
  204.                 el_rec->el_body.elmsg.msg_asc);
  205.         } break;
  206.         default: {
  207.             syslog(LOG_ALERT, "%d UNKN: %s %d/%d/%d/%d/%d",
  208.                 el_rec->elrhdr.rhdr_seqnum,
  209.                 subclass(el_rec->elsubid.subid_class),
  210.                 el_rec->elsubid.subid_type,
  211.                 el_rec->elsubid.subid_ctldevtyp,
  212.                 el_rec->elsubid.subid_num,
  213.                 el_rec->elsubid.subid_unitnum,
  214.                 el_rec->elsubid.subid_errcode);
  215.         } break;
  216.         
  217.     }
  218. }
  219. char *
  220. subclass(n)
  221. u_short n;
  222. {
  223.  
  224.     static char *p;
  225.     switch(n) {
  226.         case ELCT_MCK:        p="machine check";    break;
  227.         case ELCT_MEM:        p="mem. crd/rds";     break;
  228.         case ELCT_DISK:        p="disk errs";        break;
  229.         case ELCT_TAPE:        p="tape errs";        break;
  230.         case ELCT_DCNTL:    p="device controller errs";    break;
  231.         case ELCT_ADPTR:    p="adapter errs";    break;
  232.         case ELCT_BUS:        p="bus errs";    break;
  233.         case ELCT_SINT:        p="stray intr.";    break;
  234.         case ELCT_AWE:            p="async. write err";    break;
  235.         case ELCT_EXPTFLT:    p="panic exception/fault";    break;
  236.         case ELCT_NMIEMM:    p="8800 emm exception";    break;
  237.         case ELCT_CTE:        p="console timeout entry";    break;
  238.         case ELCT_STKDMP:    p="stack dump";    break;
  239.         case ELCT_ESR650:    p="ka650 error & status regs";    break;
  240.         case ELCT_6200_INT60:    p="vector 60 errors";    break;
  241.         case ELCT_6200_INT54:    p="vector 54 errors";    break;
  242.         case ELCT_ESR420:    p="ka420 error & status regs";    break;
  243.         case ELCT_ESRPMAX:    p="PMAX error & status regs";    break;
  244.         case ELCT_6400_INT60:    p="ka6400 vector 0x60 error";    break;
  245.         case ELCT_6400_INT54:    p="ka6400 vector 0x54 error";    break;
  246.         case ELCT_MBUS:        p="Mbus errors";    break;
  247.         case ELCT_ESR60:    p="ka60 error & status regs  ";    break;
  248.         case ELCT_ESR:        p="Generic error&status regs";    break;
  249.         case ELCT_INT60:    p="Generic vector 0x60 (hard) error";    break;
  250.         case ELCT_INT54:    p="Generic vector 0x54 (soft) error";    break;
  251.         case ELCT_9000_SYNDROME:    p="9000 syndrome entry";    break;
  252.         case ELCT_9000_KAF:    p="9000 keep alive failure from spu";    break;
  253.         case ELCT_9000_CLK:    p="9000 clock";    break;
  254.         case ELCT_9000_SCAN:    p="9000 scan";    break;
  255.         case ELCT_9000_CONFIG:    p="9000 configuration message";    break;
  256.         case ELCT_VECTOR:    p="vector";    break;
  257.         case ELSW_PNC :        p="panic (bug check)";    break;
  258.         case ELSW_CIPPD:    p="ci ppd events";    break;
  259.         case ELSW_SCS:        p="scs events";    break;
  260.         case ELMSGT_INFO:    p="info. type msg";    break;
  261.         case ELMSGT_SNAP8600:    p="8600 snapshot taken";    break;
  262.         case ELMSGT_SU:        p="start up msg";    break;
  263.         case ELMSGT_SD:        p="shutdown msg";    break;
  264.         case ELMSGT_TIM:    p="time stamp";    break;
  265.         case ELMSGT_DIAG:    p="diag. info. type msg";    break;
  266.         case ELMSGT_REPAIR:    p="repair";    break;
  267.         default:        p="unknown";    break;
  268.     }
  269.     return(p);
  270. }
  271. char *
  272. devices(el_rec)
  273. struct el_rec *el_rec;
  274. {
  275.     static char buf[1024];
  276.     switch(el_rec->elsubid.subid_type) {
  277.  
  278.         case ELFZA: { /* FZA errors */
  279.             sprintf(buf, "FZA%d, %x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x/%x",
  280.                 el_rec->el_body.el_fza.fza_id,
  281.                 el_rec->el_body.el_fza.reset_count,            /* reset counter */
  282.                 el_rec->el_body.el_fza.timestamp_hi,           /* time stamp hi */
  283.                 el_rec->el_body.el_fza.timestamp_lo,           /* time stamp lo */
  284.                 el_rec->el_body.el_fza.write_count,
  285.                 el_rec->el_body.el_fza.int_reason,             /* Internal failure reason */
  286.                 el_rec->el_body.el_fza.ext_reason,             /* External failure reason */
  287.                 el_rec->el_body.el_fza.cmd_next_ptr,           /* Next cmd entry to service */
  288.                 el_rec->el_body.el_fza.cmd_next_cmd,           /* Next cmd descr, 1st entry */
  289.                 el_rec->el_body.el_fza.dma_next_rmc_ptr,
  290.                 el_rec->el_body.el_fza.dma_next_rmc_descr,
  291.                 el_rec->el_body.el_fza.dma_next_rmc_own,
  292.                 el_rec->el_body.el_fza.dma_next_host_ptr,
  293.                 el_rec->el_body.el_fza.dma_next_host_descr,
  294.                 el_rec->el_body.el_fza.lmgr_next_ptr,
  295.                 el_rec->el_body.el_fza.lmgr_next_descr,
  296.                 el_rec->el_body.el_fza.smt_next_put_ptr,
  297.                 el_rec->el_body.el_fza.smt_next_put_descr,
  298.                 el_rec->el_body.el_fza.smt_next_take_ptr,
  299.                 el_rec->el_body.el_fza.smt_next_take_descr,
  300.                 el_rec->el_body.el_fza.pm_csr,                 /* Packet mem CSR */
  301.                 el_rec->el_body.el_fza.int_68k_present,        /* 68k interrupt ctrl reg */
  302.                 el_rec->el_body.el_fza.int_68k_mask,           /* 68k interrupt ctrl mask reg */
  303.                 el_rec->el_body.el_fza.pint_event,             /* Port interrupt reg */
  304.                 el_rec->el_body.el_fza.port_ctrl_a,            /* Port control A */
  305.                 el_rec->el_body.el_fza.port_ctrl_a_mask,       /* Port control A mask */
  306.                 el_rec->el_body.el_fza.port_ctrl_b,            /* Port control B */
  307.                 el_rec->el_body.el_fza.port_status,            /* Port status */
  308.                 el_rec->el_body.el_fza.ram_rom_map,            /* Map register */
  309.                 el_rec->el_body.el_fza.phy_csr,                /* Phy CSR */
  310.                 el_rec->el_body.el_fza.dma_done,               /* DMA done */
  311.                 el_rec->el_body.el_fza.dma_err,                /* DMA error */
  312.                 el_rec->el_body.el_fza.dma_start_lo,           /* DMA start dma low addr */
  313.                 el_rec->el_body.el_fza.dma_start_hi,           /* DMA start high addr */
  314.                 el_rec->el_body.el_fza.rmc_cmd,                /* RMC command */
  315.                 el_rec->el_body.el_fza.rmc_mode,               /* RMC mode */
  316.                 el_rec->el_body.el_fza.rmc_rcv_page,           /* RMC rcv page */
  317.                 el_rec->el_body.el_fza.rmc_rcv_params,         /* RMC rcv parameters */
  318.                 el_rec->el_body.el_fza.rmc_xmt_page,           /* RMC xmt page */
  319.                 el_rec->el_body.el_fza.rmc_xmt_params,         /* RMC xmt parameters */
  320.                 el_rec->el_body.el_fza.rmc_interrupts,         /* RMC interrupts */
  321.                 el_rec->el_body.el_fza.rmc_int_mask,           /* RMC interrupt mask */
  322.                 el_rec->el_body.el_fza.rmc_chan_status,        /* RMC channel status */
  323.                 el_rec->el_body.el_fza.mac_rcv_cntrl,          /* MAC */
  324.                 el_rec->el_body.el_fza.mac_xmt_cntrl,
  325.                 el_rec->el_body.el_fza.mac_int_mask_a,
  326.                 el_rec->el_body.el_fza.mac_int_mask_b,
  327.                 el_rec->el_body.el_fza.mac_rcv_status,
  328.                 el_rec->el_body.el_fza.mac_xmt_status,
  329.                 el_rec->el_body.el_fza.mac_mla_a,
  330.                 el_rec->el_body.el_fza.mac_mla_b,
  331.                 el_rec->el_body.el_fza.mac_mla_c,
  332.                 el_rec->el_body.el_fza.mac_t_req,
  333.                 el_rec->el_body.el_fza.mac_tvx_value);
  334.             return(buf);
  335.         } break;
  336.         case ELSCSI_CNTRL:
  337.         case ELCI_RDCNT:
  338.         case ELCI_ATTN:
  339.         case ELCI_LPKT:
  340.         case ELUQ_ATTN:
  341.         case ELBI_BLA:
  342.         case ELBI_BVP:
  343.         case ELMSCP_CNTRL:
  344.         case ELTMSCP_CNTRL:
  345.         case ELMSI_ATTN:
  346.         case ELMSI_LPKT:
  347.         case ELBI_XNA:
  348.         case ELXMI_XNA:
  349.         case ELVME_DEV_CNTL:
  350.         default: {
  351.             strcpy(buf, "undefined device error");
  352.             return(buf);
  353.         }
  354.     }
  355. }
  356.