home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume40 / nocol / part22 < prev    next >
Encoding:
Text File  |  1993-11-24  |  76.1 KB  |  2,579 lines

  1. Newsgroups: comp.sources.misc
  2. From: vikas@jvnc.net (Vikas Aggarwal)
  3. Subject: v40i152:  nocol - Network Monitoring System, Part22/26
  4. Message-ID: <1993Nov24.163830.1912@sparky.sterling.com>
  5. X-Md4-Signature: 9e9b9aba6a32b4346c7a49e33adb0806
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Wed, 24 Nov 1993 16:38:30 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: vikas@jvnc.net (Vikas Aggarwal)
  12. Posting-number: Volume 40, Issue 152
  13. Archive-name: nocol/part22
  14. Environment: INET, UNIX
  15.  
  16. #! /bin/sh
  17. # This is a shell archive.  Remove anything before this line, then feed it
  18. # into a shell via "sh file" or similar.  To overwrite existing files,
  19. # type "sh file -c".
  20. # Contents:  nocol-3.0/src/cmu-snmp/apps/snmp_vars.h
  21. #   nocol-3.0/src/cmu-snmp/apps/snmpwalk.c nocol-3.0/src/doc/noclogd.8
  22. #   nocol-3.0/src/eventselect/proc_datafile.c
  23. #   nocol-3.0/src/lib/bstring.c nocol-3.0/src/netmon/setup_display.c
  24. #   nocol-3.0/src/nsmon/nsmon.c nocol-3.0/src/perlnocol/idlemodemmon
  25. #   nocol-3.0/src/perlnocol/modemmon nocol-3.0/src/perlnocol/novellmon
  26. #   nocol-3.0/src/pingmon/Makefile
  27. #   nocol-3.0/src/support/mping/msummary
  28. #   nocol-3.0/src/support/mping/t-msummary
  29. # Wrapped by kent@sparky on Tue Nov  9 22:22:26 1993
  30. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  31. echo If this archive is complete, you will see the following message:
  32. echo '          "shar: End of archive 22 (of 26)."'
  33. if test -f 'nocol-3.0/src/cmu-snmp/apps/snmp_vars.h' -a "${1}" != "-c" ; then 
  34.   echo shar: Will not clobber existing file \"'nocol-3.0/src/cmu-snmp/apps/snmp_vars.h'\"
  35. else
  36.   echo shar: Extracting \"'nocol-3.0/src/cmu-snmp/apps/snmp_vars.h'\" \(5636 characters\)
  37.   sed "s/^X//" >'nocol-3.0/src/cmu-snmp/apps/snmp_vars.h' <<'END_OF_FILE'
  38. X/*
  39. X * Definitions for SNMP (RFC 1067) agent variable finder.
  40. X *
  41. X *
  42. X/***********************************************************
  43. X    Copyright 1988, 1989 by Carnegie Mellon University
  44. X    Copyright 1989    TGV, Incorporated
  45. X
  46. X              All Rights Reserved
  47. X
  48. XPermission to use, copy, modify, and distribute this software and its
  49. Xdocumentation for any purpose and without fee is hereby granted,
  50. Xprovided that the above copyright notice appear in all copies and that
  51. Xboth that copyright notice and this permission notice appear in
  52. Xsupporting documentation, and that the name of CMU and TGV not be used
  53. Xin advertising or publicity pertaining to distribution of the software
  54. Xwithout specific, written prior permission.
  55. X
  56. XCMU AND TGV DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  57. XINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  58. XEVENT SHALL CMU OR TGV BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  59. XCONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  60. XUSE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  61. XOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  62. XPERFORMANCE OF THIS SOFTWARE.
  63. X******************************************************************/
  64. X
  65. Xu_char    *var_system();
  66. Xu_char    *var_ifEntry();
  67. Xu_char    *var_atEntry();
  68. Xu_char    *var_ip();
  69. Xu_char    *var_ipAddrEntry();
  70. Xu_char    *var_ipRouteEntry();
  71. Xu_char    *var_icmp();
  72. Xu_char    *var_tcp();
  73. Xu_char    *var_udp();
  74. Xu_char    *var_process();
  75. Xu_char    *var_event();
  76. Xu_char    *getStatPtr();
  77. X
  78. Xextern long long_return;
  79. Xextern u_char return_buf[];
  80. X
  81. X#define INST    0xFFFFFFFF    /* used to fill out the instance field of the variables table */
  82. X
  83. X/*
  84. X * These are unit magic numbers for each variable.
  85. X */
  86. X
  87. X#define VERSION_DESCR    0
  88. X#define VERSION_ID    1
  89. X#define IFNUMBER    2
  90. X#define UPTIME        3
  91. X#define EVENTNEXTINDEX    4
  92. X
  93. X
  94. X#define IFINDEX        1
  95. X#define IFDESCR        2
  96. X#define IFTYPE        3
  97. X#define IFMTU        4
  98. X#define IFSPEED        5
  99. X#define IFPHYSADDRESS    6
  100. X#define IFADMINSTATUS    7
  101. X#define IFOPERSTATUS    8
  102. X#define IFLASTCHANGE    9
  103. X#define IFINOCTETS    10
  104. X#define IFINUCASTPKTS    11
  105. X#define IFINNUCASTPKTS    12
  106. X#define IFINDISCARDS    13
  107. X#define IFINERRORS    14
  108. X#define IFINUNKNOWNPROTOS 15
  109. X#define IFOUTOCTETS    16
  110. X#define IFOUTUCASTPKTS    17
  111. X#define IFOUTNUCASTPKTS 18
  112. X#define IFOUTDISCARDS    19
  113. X#define IFOUTERRORS    20
  114. X#define IFOUTQLEN    21
  115. X
  116. X#define ATIFINDEX    0
  117. X#define ATPHYSADDRESS    1
  118. X#define ATNETADDRESS    2
  119. X
  120. X#define IPFORWARDING    0
  121. X#define IPDEFAULTTTL    1
  122. X#define IPINRECEIVES    2
  123. X#define IPINHDRERRORS    3
  124. X#define IPINADDRERRORS    4
  125. X#define IPFORWDATAGRAMS 5
  126. X#define IPINUNKNOWNPROTOS 6
  127. X#define IPINDISCARDS    7
  128. X#define IPINDELIVERS    8
  129. X#define IPOUTREQUESTS    9
  130. X#define IPOUTDISCARDS    10
  131. X#define IPOUTNOROUTES    11
  132. X#define IPREASMTIMEOUT    12
  133. X#define IPREASMREQDS    13
  134. X#define IPREASMOKS    14
  135. X#define IPREASMFAILS    15
  136. X#define IPFRAGOKS    16
  137. X#define IPFRAGFAILS    17
  138. X#define IPFRAGCREATES    18
  139. X
  140. X#define IPADADDR    1
  141. X#define IPADIFINDEX    2
  142. X#define IPADNETMASK    3
  143. X#define IPADBCASTADDR    4
  144. X
  145. X#define IPROUTEDEST    0
  146. X#define IPROUTEIFINDEX    1
  147. X#define IPROUTEMETRIC1    2
  148. X#define IPROUTEMETRIC2    3
  149. X#define IPROUTEMETRIC3    4
  150. X#define IPROUTEMETRIC4    5
  151. X#define IPROUTENEXTHOP    6
  152. X#define IPROUTETYPE    7
  153. X#define IPROUTEPROTO    8
  154. X#define IPROUTEAGE    9
  155. X
  156. X#define ICMPINMSGS         0
  157. X#define ICMPINERRORS         1
  158. X#define ICMPINDESTUNREACHS   2
  159. X#define ICMPINTIMEEXCDS      3
  160. X#define ICMPINPARMPROBS      4
  161. X#define ICMPINSRCQUENCHS     5
  162. X#define ICMPINREDIRECTS      6
  163. X#define ICMPINECHOS         7
  164. X#define ICMPINECHOREPS         8
  165. X#define ICMPINTIMESTAMPS     9
  166. X#define ICMPINTIMESTAMPREPS 10
  167. X#define ICMPINADDRMASKS     11
  168. X#define ICMPINADDRMASKREPS  12
  169. X#define ICMPOUTMSGS        13
  170. X#define ICMPOUTERRORS        14
  171. X#define ICMPOUTDESTUNREACHS 15
  172. X#define ICMPOUTTIMEEXCDS    16
  173. X#define ICMPOUTPARMPROBS    17
  174. X#define ICMPOUTSRCQUENCHS   18
  175. X#define ICMPOUTREDIRECTS    19
  176. X#define ICMPOUTECHOS        20
  177. X#define ICMPOUTECHOREPS     21
  178. X#define ICMPOUTTIMESTAMPS   22
  179. X#define ICMPOUTTIMESTAMPREPS 23
  180. X#define ICMPOUTADDRMASKS    24
  181. X#define ICMPOUTADDRMASKREPS 25
  182. X
  183. X#define TCPRTOALGORITHM      1
  184. X#define TCPRTOMIN         2
  185. X#define TCPRTOMAX         3
  186. X#define TCPMAXCONN         4
  187. X#define TCPACTIVEOPENS         5
  188. X#define TCPPASSIVEOPENS      6
  189. X#define TCPATTEMPTFAILS      7
  190. X#define TCPESTABRESETS         8
  191. X#define TCPCURRESTAB         9
  192. X#define TCPINSEGS        10
  193. X#define TCPOUTSEGS        11
  194. X#define TCPRETRANSSEGS        12
  195. X#define TCPCONNSTATE        13
  196. X#define TCPCONNLOCALADDRESS 14
  197. X#define TCPCONNLOCALPORT    15
  198. X#define TCPCONNREMADDRESS   16
  199. X#define TCPCONNREMPORT        17
  200. X
  201. X#define UDPINDATAGRAMS        0
  202. X#define UDPNOPORTS        1
  203. X#define UDPINERRORS        2
  204. X#define UDPOUTDATAGRAMS     3
  205. X
  206. X#define EVENTCLASS            0
  207. X#define EVENTINSTANCE            1
  208. X#define EVENTALARMTYPE            2
  209. X#define EVENTTIME            3
  210. X#define EVENTPROBCAUSE            4
  211. X#define EVENTSPECIFICPROBLEM        5
  212. X#define EVENTSEVERITY            6
  213. X#define EVENTBACKUPSTATUS        7
  214. X#define EVENTBACKUPINSTANCE        8
  215. X#define EVENTTREND            9
  216. X#define EVENTTHRESHOLD            10
  217. X#define EVENTTHRESHOLDLEVEL        11
  218. X#define EVENTTHRESHOLDOBSVALUE        12
  219. X#define EVENTID                13
  220. X#define EVENTCORRELATIONS        14
  221. X#define EVENTOPERSTATE            16
  222. X#define EVENTADMINSTATE            17
  223. X#define EVENTMONATTRIBUTES        18
  224. X#define EVENTREPAIRACTION        19
  225. X#define EVENTDATA            20
  226. X#define EVENTTEXT            21
  227. X#define EVENTCREDIBILITY        22
  228. X#define EVENTINDEX            23
  229. X#define EVENTVALID            24
  230. X
  231. X
  232. Xstruct variable {
  233. X    oid            name[26];        /* object identifier of variable */
  234. X    u_char        namelen;        /* length of above */
  235. X    char        type;        /* type of variable, INTEGER or (octet) STRING */
  236. X    u_char        magic;        /* passed to function as a hint */
  237. X    u_short        acl;        /* access control list for variable */
  238. X    u_char        *(*findVar)();  /* function that finds variable */
  239. X};
  240. END_OF_FILE
  241.   if test 5636 -ne `wc -c <'nocol-3.0/src/cmu-snmp/apps/snmp_vars.h'`; then
  242.     echo shar: \"'nocol-3.0/src/cmu-snmp/apps/snmp_vars.h'\" unpacked with wrong size!
  243.   fi
  244.   # end of 'nocol-3.0/src/cmu-snmp/apps/snmp_vars.h'
  245. fi
  246. if test -f 'nocol-3.0/src/cmu-snmp/apps/snmpwalk.c' -a "${1}" != "-c" ; then 
  247.   echo shar: Will not clobber existing file \"'nocol-3.0/src/cmu-snmp/apps/snmpwalk.c'\"
  248. else
  249.   echo shar: Extracting \"'nocol-3.0/src/cmu-snmp/apps/snmpwalk.c'\" \(4780 characters\)
  250.   sed "s/^X//" >'nocol-3.0/src/cmu-snmp/apps/snmpwalk.c' <<'END_OF_FILE'
  251. X/*
  252. X * snmpwalk.c - send snmp GETNEXT requests to a network entity, walking a subtree.
  253. X *
  254. X */
  255. X/***********************************************************
  256. X    Copyright 1988, 1989 by Carnegie Mellon University
  257. X
  258. X                      All Rights Reserved
  259. X
  260. XPermission to use, copy, modify, and distribute this software and its 
  261. Xdocumentation for any purpose and without fee is hereby granted, 
  262. Xprovided that the above copyright notice appear in all copies and that
  263. Xboth that copyright notice and this permission notice appear in 
  264. Xsupporting documentation, and that the name of CMU not be
  265. Xused in advertising or publicity pertaining to distribution of the
  266. Xsoftware without specific, written prior permission.  
  267. X
  268. XCMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  269. XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  270. XCMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  271. XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  272. XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  273. XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  274. XSOFTWARE.
  275. X******************************************************************/
  276. X#include <sys/types.h>
  277. X#include <netinet/in.h>
  278. X#include <stdio.h>
  279. X
  280. X#include "snmp.h"
  281. X#include "snmp_impl.h"
  282. X#include "asn1.h"
  283. X#include "snmp_api.h"
  284. X#include "snmp_client.h"
  285. X
  286. Xoid objid_mib[] = {1, 3, 6, 1, 2, 1};
  287. X
  288. Xint    snmp_dump_packet = 0;
  289. X
  290. X
  291. Xmain(argc, argv)
  292. X    int        argc;
  293. X    char    *argv[];
  294. X{
  295. X    struct snmp_session    session, *ss;
  296. X    struct snmp_pdu *pdu, *response;
  297. X    struct variable_list *vars;
  298. X    int    arg;
  299. X    char *gateway = NULL;
  300. X    char *community = NULL;
  301. X    int gotroot = 0;
  302. X    oid    name[32];
  303. X    int name_length;
  304. X    oid root[MAX_NAME_LEN];
  305. X    int    rootlen, count;
  306. X    int running;
  307. X    int status;
  308. X
  309. X    init_mib();
  310. X    /*
  311. X     * usage: snmpwalk gateway-name community-name [object-id]
  312. X     */
  313. X    for(arg = 1; arg < argc; arg++){
  314. X    if (argv[arg][0] == '-'){
  315. X        switch(argv[arg][1]){
  316. X        case 'd':
  317. X            snmp_dump_packet++;
  318. X            break;
  319. X        default:
  320. X            printf("invalid option: -%c\n", argv[arg][1]);
  321. X            break;
  322. X        }
  323. X        continue;
  324. X    }
  325. X    if (gateway == NULL){
  326. X        gateway = argv[arg];
  327. X    } else if (community == NULL){
  328. X        community = argv[arg]; 
  329. X    } else {
  330. X        rootlen = MAX_NAME_LEN;
  331. X        if (read_objid(argv[arg], root, &rootlen)){
  332. X        gotroot = 1;
  333. X        } else {
  334. X        printf("Invalid object identifier: %s\n", argv[arg]);
  335. X        }
  336. X    }
  337. X    }
  338. X
  339. X    if (gotroot == 0){
  340. X    bcopy((char *)objid_mib, (char *)root, sizeof(objid_mib));
  341. X    rootlen = sizeof(objid_mib) / sizeof(oid);
  342. X    gotroot = 1;
  343. X    }
  344. X
  345. X    if (!(gateway && community && gotroot == 1)){
  346. X    printf("usage: snmpwalk gateway-name community-name object-identifier\n");
  347. X    exit(1);
  348. X    }
  349. X
  350. X    bzero((char *)&session, sizeof(struct snmp_session));
  351. X    session.peername = gateway;
  352. X    session.community = (u_char *)community;
  353. X    session.community_len = strlen((char *)community);
  354. X    session.retries = SNMP_DEFAULT_RETRIES;
  355. X    session.timeout = SNMP_DEFAULT_TIMEOUT;
  356. X    session.authenticator = NULL;
  357. X    snmp_synch_setup(&session);
  358. X    ss = snmp_open(&session);
  359. X    if (ss == NULL){
  360. X    printf("Couldn't open snmp\n");
  361. X    exit(-1);
  362. X    }
  363. X
  364. X    bcopy((char *)root, (char *)name, rootlen * sizeof(oid));
  365. X    name_length = rootlen;
  366. X
  367. X    running = 1;
  368. X    while(running){
  369. X    running = 0;
  370. X    pdu = snmp_pdu_create(GETNEXT_REQ_MSG);
  371. X
  372. X    snmp_add_null_var(pdu, name, name_length);
  373. X
  374. X    status = snmp_synch_response(ss, pdu, &response);
  375. X    if (status == STAT_SUCCESS){
  376. X        if (response->errstat == SNMP_ERR_NOERROR){
  377. X        for(vars = response->variables; vars; vars = vars->next_variable){
  378. X            if (vars->name_length < rootlen || bcmp(root, vars->name, rootlen * sizeof(oid)))
  379. X            continue;    /* not part of this subtree */
  380. X            print_variable(vars->name, vars->name_length, vars);
  381. X            bcopy((char *)vars->name, (char *)name, vars->name_length * sizeof(oid));
  382. X            name_length = vars->name_length;
  383. X            running = 1; /* restart so we can get next variable */
  384. X        }
  385. X        } else {
  386. X        if (response->errstat == SNMP_ERR_NOSUCHNAME){
  387. X            printf("End of MIB.\n");
  388. X        } else {
  389. X            printf("Error in packet.\nReason: %s\n", snmp_errstring(response->errstat));
  390. X            if (response->errstat == SNMP_ERR_NOSUCHNAME){
  391. X            printf("The request for this object identifier failed: ");
  392. X            for(count = 1, vars = response->variables; vars && count != response->errindex;
  393. X                vars = vars->next_variable, count++)
  394. X                ;
  395. X            if (vars)
  396. X                print_objid(vars->name, vars->name_length);
  397. X            printf("\n");
  398. X            }
  399. X        }
  400. X        }
  401. X
  402. X    } else if (status == STAT_TIMEOUT){
  403. X        printf("No Response from %s\n", gateway);
  404. X    } else {    /* status == STAT_ERROR */
  405. X        printf("An error occurred, Quitting\n");
  406. X    }
  407. X
  408. X    if (response)
  409. X        snmp_free_pdu(response);
  410. X    }
  411. X    snmp_close(ss);
  412. X}
  413. X
  414. END_OF_FILE
  415.   if test 4780 -ne `wc -c <'nocol-3.0/src/cmu-snmp/apps/snmpwalk.c'`; then
  416.     echo shar: \"'nocol-3.0/src/cmu-snmp/apps/snmpwalk.c'\" unpacked with wrong size!
  417.   fi
  418.   # end of 'nocol-3.0/src/cmu-snmp/apps/snmpwalk.c'
  419. fi
  420. if test -f 'nocol-3.0/src/doc/noclogd.8' -a "${1}" != "-c" ; then 
  421.   echo shar: Will not clobber existing file \"'nocol-3.0/src/doc/noclogd.8'\"
  422. else
  423.   echo shar: Extracting \"'nocol-3.0/src/doc/noclogd.8'\" \(5371 characters\)
  424.   sed "s/^X//" >'nocol-3.0/src/doc/noclogd.8' <<'END_OF_FILE'
  425. X.\" $Header: /home/aggarwal/lsrc/nocol/src/doc/RCS/noclogd.8,v 1.2 1993/10/28 16:38:03 aggarwal Exp $
  426. X.\"
  427. X.TH NOCLOGD 8 "Oct 1 1993"
  428. X.SH NAME
  429. Xnoclogd \- NOCOL event logging daemon
  430. X.SH SYNOPSIS
  431. X.B noclogd
  432. X[
  433. X.B \-d
  434. X] [
  435. X.B \-e
  436. X.I output-error-filename
  437. X] [
  438. X.B \-f
  439. X.I config-filename
  440. X]
  441. X.LP
  442. XThe
  443. X.I noclogd
  444. Xdaemon logs NOCOL events to the files specified in the config file, based
  445. Xon the loglevels specified. Alternately, it can open a pipe to a process
  446. Xand run that process instead of writing to a file.
  447. X.SH OPTIONS
  448. X.TP
  449. X.B \-d
  450. XFor debug mode. Will not daemonize and writes errrors to terminal.
  451. X.TP
  452. X.B \-e 
  453. X.I <errorfile>
  454. XFor writing out errors to. Default is \fI ETCDIR/noclogd.errors\fR
  455. X.TP
  456. X.B \-f 
  457. X.I <config filename>
  458. XLocation of the configuration file. Default is \fI ETCDIR/noclogd.cf\fR
  459. X
  460. X.SH DESCRIPTION
  461. X.LP
  462. XThe
  463. X.B noclogd
  464. Xdaemon is the logging daemon for the NOCOL network monitoring program.
  465. XIt listens on a UDP port (2325) for the various nocol monitors to send
  466. Xit EVENT structures. It then logs these events (as
  467. X.I text
  468. Xlines), to various output files depending of the configuration file
  469. Xfor the daemon. Alternatively, the output can be piped to a program
  470. Xto be executed. The logging methodology is similar to the Unix
  471. X.B syslog
  472. Xfacility.
  473. XThe format of the
  474. X.I noclogd
  475. Xlog lines are:
  476. X.RS
  477. X.I date
  478. X[
  479. X.I sender
  480. X]: SITE
  481. X.I sitename address
  482. XVAR
  483. X.I varname value threshold units
  484. XLEVEL
  485. X.I severity
  486. XLOGLEVEL
  487. X.I log severity
  488. XNOCOP
  489. X.I up down unknown test
  490. X.RE
  491. X.LP
  492. XSending a HUP signal to the server closes all streams currently open, and
  493. Xreopens them. This is useful if you move the old log files every night
  494. Xor so.
  495. X
  496. XFor security, only the hosts specified in the configuration file
  497. Xare allowed to send log messages.
  498. X
  499. X.SH DESIGN CONSIDERATIONS
  500. X.LP
  501. XThe following are important 'features' about
  502. X.B noclogd
  503. Xthat should be kept in mind while logging and running programs through it:
  504. X.RS
  505. X.TP 3
  506. X1.
  507. XSince the sockets used are of the UDP type, datagrams can be lost if
  508. Xtoo many events are sent to the daemon at the same time. However, since
  509. Xthe monitors only log events when a state changes, this is usually not
  510. Xa problem. Additionally, there is a counter in the
  511. X.I eventlog()
  512. Xcall to pause for a second after logging 100 events.
  513. X.TP 3
  514. X2.
  515. XSecurity is implemented by allowing only a select list of IP addresses
  516. Xto log (specified in the configuration file). The IP address of the
  517. Xhost sending the packets is verified using the 
  518. X.IR recvfrom (2)
  519. Xsystem call. Note however, that there is no way to prevent malicious
  520. Xusers on a permitted system from sending invalid junk data to the monitor
  521. X(there is no password scheme implemented). Anyone from a valid machine
  522. Xcan log events to the 
  523. X.I noclogd
  524. Xdaemon.
  525. X.TP 3
  526. X3.
  527. XThe daemon does not
  528. X.I fork(2)
  529. Xoff a child for each packet that comes in. It processes each event 
  530. Xitself. Thus,if you are piping the output to a program 
  531. X(instead of logging to a file), then make sure that the program being 
  532. Xrun does its main procesing in the background and returns control to
  533. Xthe noclogd daemon as soon as possible.
  534. X.I i.e.
  535. Xthe various output programs being executed are responsible for doing
  536. Xtheir own "fork-ing", the daemon will not do it for them, and might
  537. Xlose other incoming log packets if the piped process does not release the
  538. Xstdin.
  539. X.TP 3
  540. X4.
  541. XThe hostname on which the 
  542. X.I noclogd
  543. Xdaemon runs, is compiled during runtime so that the various NOCOL
  544. Xmonitors know the system on which the logging daemon runs. Typically,
  545. Xit is easier to define this (in 
  546. X.IR noclogd.h )
  547. Xas
  548. X.I noclog.your.domain
  549. Xand create a CNAME for it in the nameserver.
  550. X.TP 3
  551. X5.
  552. XThe server might not be running when the various monitors startup.
  553. XHence, the library subroutine
  554. X.I eventlog()
  555. Xtries to log to the server only if it hasn't attempted to do so in 
  556. Xthe past 60 secs (RETRY_REOPEN).
  557. X.RE
  558. X
  559. X.SH CONFIG FILE
  560. XThe configuration file format is:
  561. X.RS
  562. X.sp .5
  563. X.nf
  564. X# Comments begin with a # character.
  565. X#
  566. X# The following hosts are permitted to log entries to this daemon:
  567. Xpermithosts     127.0.0.1  128.121.50.2 128.121.50.7
  568. Xpermithosts     128.121.50.145
  569. X##
  570. X## Give full pathnames in filenames since the daemon changes dir.
  571. X##
  572. X## SENDER       LEVEL           LOGFILE or PIPEFILE
  573. X##
  574. X*               critical        /nocol/logs/log-critical
  575. Xnsmon           error           /nocol/logs/log-error
  576. Xtest            warning         /nocol/logs/log-warning
  577. X*               info            /nocol/logs/log-info
  578. X#
  579. Xpingmon         critical        |/nocol/bin/beeper
  580. X.fi
  581. X.RE
  582. XComments begin with a '#' and sender names can be specified as '*' to
  583. Xindicate a wildcard. Keep in mind that an event is logged to all streams
  584. Xwith a severity lower than its severity/loglevel. Thus, in the above example,
  585. Xevents with a loglevel of ERROR will be logged to all the 3 files
  586. X.I log-info, log-warning & log-error.
  587. X
  588. X.SH FUTURE DEVELOPMENTS
  589. X.LP
  590. XPossible future enhancements are:
  591. X.RS
  592. X.TP 3
  593. X1.
  594. XCreating another daemon that does all the time consuming 'work' with a 
  595. Xsort of queue mechanism.
  596. X.TP 3
  597. X2.
  598. XListening on a STREAM socket also, so that some monitors (who so desire)
  599. Xcan open a STREAM connection and spew events down this reliable connection.
  600. X
  601. X.SH AUTHOR
  602. X.nf
  603. XVikas Aggarwal, JvNCnet, GES (vikas@jvnc.net) 
  604. XDavid Wagner (wagner@jvnc.net).
  605. X.fi
  606. X.SH SEE ALSO
  607. Xnocol(1) nocol-prog(3) perlnocol(3)
  608. Xeventselect(8) genmon(8) noclogd(8) nocol-overview(8)
  609. Xnocol-utility(8) nsmon(8) pingmon(8) portmon(8) 
  610. Xtpmon(8) trapmon(8)
  611. END_OF_FILE
  612.   if test 5371 -ne `wc -c <'nocol-3.0/src/doc/noclogd.8'`; then
  613.     echo shar: \"'nocol-3.0/src/doc/noclogd.8'\" unpacked with wrong size!
  614.   fi
  615.   # end of 'nocol-3.0/src/doc/noclogd.8'
  616. fi
  617. if test -f 'nocol-3.0/src/eventselect/proc_datafile.c' -a "${1}" != "-c" ; then 
  618.   echo shar: Will not clobber existing file \"'nocol-3.0/src/eventselect/proc_datafile.c'\"
  619. else
  620.   echo shar: Extracting \"'nocol-3.0/src/eventselect/proc_datafile.c'\" \(4498 characters\)
  621.   sed "s/^X//" >'nocol-3.0/src/eventselect/proc_datafile.c' <<'END_OF_FILE'
  622. X/*+ 
  623. X * $Header: /home/aggarwal/lsrc/nocol/src/eventselect/RCS/proc_datafile.c,v 1.2 1993/10/30 03:18:33 aggarwal Exp $
  624. X */
  625. X
  626. X/* Copyright 1993 JvNCnet, Global Enterprise Services */
  627. X
  628. X/*+ 
  629. X * FUNCTION:
  630. X *     This program processes each open file descriptor that is
  631. X * passed to it. If the severity + sender string + sitename + time
  632. X * match, then it prints/logs the line in the NOCOL format.
  633. X *
  634. X */
  635. X
  636. X/*+
  637. X * $Log: proc_datafile.c,v $
  638. X * Revision 1.2  1993/10/30  03:18:33  aggarwal
  639. X * Now uses get_date() instead of the Sun specific  timelocal() call
  640. X *
  641. X * Revision 1.1  1993/10/02  05:23:56  aggarwal
  642. X * Initial revision
  643. X *
  644. X *
  645. X */
  646. X
  647. X#include <stdio.h>
  648. X#ifdef ultrix
  649. X#include <time.h>
  650. X#else
  651. X#include <sys/time.h>
  652. X#endif
  653. X
  654. X#include "nocol.h"
  655. X
  656. Xstatic struct tm curtm;            /* present time in tm structure    */
  657. Xchar   *event_to_logstr();        /* format event in string format */  
  658. X
  659. Xextern  char    **senderlist, **sitenamelist ;    /* defined in main() */
  660. Xextern  int    minseverity, logevents, debugflag ;
  661. Xextern  time_t    fromtime, totime;
  662. X
  663. Xproc_datafile (fd)
  664. X     int fd;                /* file descriptor  */
  665. X{
  666. X    static EVENT null_event ;        /* all null for testing    */
  667. X    EVENT v;                /* storage for the event  */
  668. X    int status, bufsize;        /* for exit status   */
  669. X    time_t locclock ;
  670. X
  671. X    /* get present time and keep it constant while processing the entire
  672. X    ** data file (don't add processing delay to the delta times).
  673. X    */
  674. X    
  675. X    locclock = time ((long *)NULL);
  676. X    bcopy(localtime ((long *)&locclock), &curtm, sizeof curtm);
  677. X
  678. X    /*+
  679. X     * Need a bcmp test to ensure that the read event was not a NULL
  680. X     * event (all zeroes) as could happen if a NFS file was moved
  681. X     * while another process (e.g. display) is processing the file
  682. X     * and has it open for reading.
  683. X     */
  684. X
  685. X    /*
  686. X     * Now read in a event and check severity, sender, sitename, times
  687. X     */
  688. X    while ((bufsize=read (fd, (char *)&v, sizeof(v))) == sizeof (v))
  689. X      if (bcmp(v, null_event, sizeof(v)) != 0)        /* Not null event  */
  690. X      {
  691. X      if ((int)v.severity  <= minseverity)
  692. X        if (check_strlist(&senderlist, v.sender))
  693. X          if (check_strlist(&sitenamelist, v.site.name))
  694. X        if (check_event_time(&v))
  695. X        {
  696. X            if (logevents)
  697. X              eventlog(&v);
  698. X            else
  699. X              printf("%s", event_to_logstr(&v));
  700. X        }
  701. X      }    /* end:  if (!null event)  */
  702. X
  703. X    if (bufsize == 0)            /* end of the file  */
  704. X      status = 0;
  705. X    else                /* some read error  */
  706. X      status = -1;
  707. X    return (status);    
  708. X
  709. X}    /* end:  proc_datafile()  */
  710. X
  711. X/*+ 
  712. X * FUNCTION:
  713. X *     Check string list for matching string. Use of 'strncasecmp' looks
  714. X * for a match from the beginning of the string, whereas 'strstr' looks
  715. X * for a substring match but does not do ignore-case.
  716. X */
  717. Xcheck_strlist(slist, S)
  718. X     char **slist, *S ;    /* command line list of strings vs. EVENT string */
  719. X{
  720. X    register i = 0 ; 
  721. X    static char s[256];
  722. X
  723. X    /* nothing to compare against */
  724. X    if (slist == NULL || *slist == NULL || s == NULL)
  725. X      return (1);
  726. X
  727. X    while ( (s[i] =  tolower(S[i]) )  )        /* lowercase the string */
  728. X      ++i ;
  729. X
  730. X    i = 0;
  731. X
  732. X#ifdef DEBUG
  733. X    if (debugflag)
  734. X      fprintf(stderr,
  735. X          "debug (check_strlist): checking for '%s' in list '%s'...\n",
  736. X          s, slist[0]);
  737. X#endif
  738. X    while (slist[i])
  739. X      if (strstr(s, slist[i]) != NULL)    /* cmd line 'slist' can be substring */
  740. X/*      if (strncasecmp(s, slist[i], strlen(slist[i]))  == 0 ) /* */
  741. X      {
  742. X#ifdef DEBUG
  743. X      fprintf(stderr, "debug (check_strlist): matched %s\n", slist[i]);
  744. X#endif
  745. X      return (1);
  746. X      }
  747. X      else
  748. X      {
  749. X#ifdef DEBUG
  750. X      fprintf(stderr, "debug (check_strlist): failed %s\n", slist[i]);
  751. X#endif
  752. X      ++i ;
  753. X      }
  754. X
  755. X    return(0) ;                /* failure */
  756. X}
  757. X
  758. X/*+ 
  759. X * FUNCTION:
  760. X *     Check event time to see if they fall in the user specified
  761. X * command line time ranges.
  762. X**/
  763. Xcheck_event_time(pv)
  764. X     EVENT  *pv;
  765. X{
  766. X    struct tm tm ;
  767. X    time_t eventtime ;
  768. X
  769. X    bcopy (&curtm, &tm, sizeof(tm));    /* current time */
  770. X
  771. X    if (tm.tm_mon < (int)pv->mon - 1)
  772. X      tm.tm_year -= 1 ;            /* previous year */
  773. X
  774. X    tm.tm_mon = pv->mon - 1;    tm.tm_mday = pv->day ;
  775. X    tm.tm_hour = pv->hour ;    tm.tm_min = pv->min ;
  776. X
  777. X/*    eventtime = timelocal(&tm) ;    /* Only on SunOS ? */
  778. X    eventtime = get_date(asctime(&tm), NULL); /* convert to secs since 1970 */
  779. X
  780. X#ifdef DEBUG
  781. X    if (debugflag)
  782. X      fprintf(stderr,
  783. X          "debug (event_time): fromtime/eventtime/totime = %ld/%ld/%ld\n",
  784. X          fromtime, eventtime, totime);
  785. X#endif
  786. X    if (eventtime > fromtime  &&  eventtime < totime)
  787. X      return (1);
  788. X    else
  789. X      return(0);
  790. X}
  791. X
  792. END_OF_FILE
  793.   if test 4498 -ne `wc -c <'nocol-3.0/src/eventselect/proc_datafile.c'`; then
  794.     echo shar: \"'nocol-3.0/src/eventselect/proc_datafile.c'\" unpacked with wrong size!
  795.   fi
  796.   # end of 'nocol-3.0/src/eventselect/proc_datafile.c'
  797. fi
  798. if test -f 'nocol-3.0/src/lib/bstring.c' -a "${1}" != "-c" ; then 
  799.   echo shar: Will not clobber existing file \"'nocol-3.0/src/lib/bstring.c'\"
  800. else
  801.   echo shar: Extracting \"'nocol-3.0/src/lib/bstring.c'\" \(4857 characters\)
  802.   sed "s/^X//" >'nocol-3.0/src/lib/bstring.c' <<'END_OF_FILE'
  803. X/* $Header: /home/aggarwal/lsrc/nocol/src/lib/RCS/bstring.c,v 1.1 1993/10/30 03:22:47 aggarwal Exp $ */
  804. X/*
  805. X * Merged bcmp(),  bzero(),  bcopy()  from BSD distribution. -vikas
  806. X */
  807. X/*
  808. X * Copyright (c) 1987 Regents of the University of California.
  809. X * All rights reserved.
  810. X *
  811. X * Redistribution and use in source and binary forms, with or without
  812. X * modification, are permitted provided that the following conditions
  813. X * are met:
  814. X * 1. Redistributions of source code must retain the above copyright
  815. X *    notice, this list of conditions and the following disclaimer.
  816. X * 2. Redistributions in binary form must reproduce the above copyright
  817. X *    notice, this list of conditions and the following disclaimer in the
  818. X *    documentation and/or other materials provided with the distribution.
  819. X * 3. All advertising materials mentioning features or use of this software
  820. X *    must display the following acknowledgement:
  821. X *    This product includes software developed by the University of
  822. X *    California, Berkeley and its contributors.
  823. X * 4. Neither the name of the University nor the names of its contributors
  824. X *    may be used to endorse or promote products derived from this software
  825. X *    without specific prior written permission.
  826. X *
  827. X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  828. X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  829. X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  830. X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  831. X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  832. X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  833. X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  834. X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  835. X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  836. X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  837. X * SUCH DAMAGE.
  838. X */
  839. X
  840. X#if defined(LIBC_SCCS) && !defined(lint)
  841. X/*static char *sccsid = "from: @(#)bcmp.c    5.6 (Berkeley) 2/24/91";*/
  842. Xstatic char *rcsid = "bcmp.c,v 1.3 1993/08/26 00:51:35 jtc Exp";
  843. X#endif /* LIBC_SCCS and not lint */
  844. X
  845. X#include <string.h>
  846. X/* #include <sys/cdefs.h>    /* */
  847. X
  848. X/*
  849. X * bcmp -- vax cmpc3 instruction
  850. X */
  851. Xbcmp(b1, b2, length)
  852. X    const void *b1, *b2;
  853. X    register size_t length;
  854. X{
  855. X    register char *p1, *p2;
  856. X
  857. X    if (length == 0)
  858. X        return(0);
  859. X    p1 = (char *)b1;
  860. X    p2 = (char *)b2;
  861. X    do
  862. X        if (*p1++ != *p2++)
  863. X            break;
  864. X    while (--length);
  865. X    return(length);
  866. X}
  867. X
  868. X
  869. X/* static char *rcsid = "bcopy.c,v 1.3 1993/08/26 00:51:36 jtc Exp"; */
  870. X
  871. X/*
  872. X * sizeof(word) MUST BE A POWER OF TWO
  873. X * SO THAT wmask BELOW IS ALL ONES
  874. X */
  875. Xtypedef    int word;        /* "word" used for optimal copy speed */
  876. X
  877. X#define    wsize    sizeof(word)
  878. X#define    wmask    (wsize - 1)
  879. X
  880. X/*
  881. X * Copy a block of memory, handling overlap.
  882. X * This is the routine that actually implements
  883. X * (the portable versions of) bcopy, memcpy, and memmove.
  884. X */
  885. X#ifdef MEMCOPY
  886. Xvoid *
  887. Xmemcpy(dst0, src0, length)
  888. X#else
  889. X#ifdef MEMMOVE
  890. Xvoid *
  891. Xmemmove(dst0, src0, length)
  892. X#else
  893. Xvoid
  894. Xbcopy(src0, dst0, length)
  895. X#endif
  896. X#endif
  897. X    void *dst0;
  898. X    const void *src0;
  899. X    register size_t length;
  900. X{
  901. X    register char *dst = dst0;
  902. X    register const char *src = src0;
  903. X    register size_t t;
  904. X
  905. X    if (length == 0 || dst == src)        /* nothing to do */
  906. X        goto done;
  907. X
  908. X    /*
  909. X     * Macros: loop-t-times; and loop-t-times, t>0
  910. X     */
  911. X#define    TLOOP(s) if (t) TLOOP1(s)
  912. X#define    TLOOP1(s) do { s; } while (--t)
  913. X
  914. X    if ((unsigned long)dst < (unsigned long)src) {
  915. X        /*
  916. X         * Copy forward.
  917. X         */
  918. X        t = (int)src;    /* only need low bits */
  919. X        if ((t | (int)dst) & wmask) {
  920. X            /*
  921. X             * Try to align operands.  This cannot be done
  922. X             * unless the low bits match.
  923. X             */
  924. X            if ((t ^ (int)dst) & wmask || length < wsize)
  925. X                t = length;
  926. X            else
  927. X                t = wsize - (t & wmask);
  928. X            length -= t;
  929. X            TLOOP1(*dst++ = *src++);
  930. X        }
  931. X        /*
  932. X         * Copy whole words, then mop up any trailing bytes.
  933. X         */
  934. X        t = length / wsize;
  935. X        TLOOP(*(word *)dst = *(word *)src; src += wsize; dst += wsize);
  936. X        t = length & wmask;
  937. X        TLOOP(*dst++ = *src++);
  938. X    } else {
  939. X        /*
  940. X         * Copy backwards.  Otherwise essentially the same.
  941. X         * Alignment works as before, except that it takes
  942. X         * (t&wmask) bytes to align, not wsize-(t&wmask).
  943. X         */
  944. X        src += length;
  945. X        dst += length;
  946. X        t = (int)src;
  947. X        if ((t | (int)dst) & wmask) {
  948. X            if ((t ^ (int)dst) & wmask || length <= wsize)
  949. X                t = length;
  950. X            else
  951. X                t &= wmask;
  952. X            length -= t;
  953. X            TLOOP1(*--dst = *--src);
  954. X        }
  955. X        t = length / wsize;
  956. X        TLOOP(src -= wsize; dst -= wsize; *(word *)dst = *(word *)src);
  957. X        t = length & wmask;
  958. X        TLOOP(*--dst = *--src);
  959. X    }
  960. Xdone:
  961. X#if defined(MEMCOPY) || defined(MEMMOVE)
  962. X    return (dst0);
  963. X#else
  964. X    return;
  965. X#endif
  966. X}
  967. X
  968. X
  969. X/*
  970. X * bzero -- vax movc5 instruction
  971. X */
  972. Xvoid
  973. Xbzero(b, length)
  974. X    void *b;
  975. X    register size_t length;
  976. X{
  977. X    register char *p;
  978. X
  979. X    for (p = b; length--;)
  980. X        *p++ = '\0';
  981. X}
  982. X
  983. END_OF_FILE
  984.   if test 4857 -ne `wc -c <'nocol-3.0/src/lib/bstring.c'`; then
  985.     echo shar: \"'nocol-3.0/src/lib/bstring.c'\" unpacked with wrong size!
  986.   fi
  987.   # end of 'nocol-3.0/src/lib/bstring.c'
  988. fi
  989. if test -f 'nocol-3.0/src/netmon/setup_display.c' -a "${1}" != "-c" ; then 
  990.   echo shar: Will not clobber existing file \"'nocol-3.0/src/netmon/setup_display.c'\"
  991. else
  992.   echo shar: Extracting \"'nocol-3.0/src/netmon/setup_display.c'\" \(4602 characters\)
  993.   sed "s/^X//" >'nocol-3.0/src/netmon/setup_display.c' <<'END_OF_FILE'
  994. X/*+ 
  995. X** $Header: /nocol/src/netmon/RCS/setup_display.c,v 1.3 1992/06/18 21:09:10 aggarwal Exp $
  996. X**/
  997. X
  998. X/* Copyright 1992 JvNCnet, Princeton */
  999. X
  1000. X/*+ 
  1001. X** FUNCTION
  1002. X**    To create all necessary windows.
  1003. X**
  1004. X** Subwindows within 'wmain' are created and changes made in them.
  1005. X** Then only 'wmain' needs to be refreshed. Each window can be treated
  1006. X** individually (and with respect (!!)).
  1007. X**
  1008. X**/
  1009. X
  1010. X/*
  1011. X * $Log: setup_display.c,v $
  1012. X * Revision 1.3  1992/06/18  21:09:10  aggarwal
  1013. X * Added check for columns also.
  1014. X *
  1015. X * Revision 1.2  1992/04/22  22:59:58  aggarwal
  1016. X * Lot of cleaning up for releasing. Organized things right.
  1017. X *
  1018. X * Revision 1.1  1990/03/09  13:06:33  aggarwal
  1019. X * Initial revision
  1020. X *
  1021. X *
  1022. X */
  1023. X#include    "netmon.h"
  1024. X
  1025. Xsetup_display()
  1026. X{
  1027. X    extern int LINES, COLS;            /* defined in curses.h    */
  1028. X    extern struct allwins aw;            /* defined in netmon.h    */
  1029. X    extern int level, options;             /* defined in netmon.h    */
  1030. X    extern char *prognm ;            /* defined in netmon.h    */
  1031. X
  1032. X    initscr ();
  1033. X    noecho();                    /* else messes up curses */
  1034. X    cbreak();                    /* don't buffer input */
  1035. X
  1036. X    if ( COLS < MNCOLS )
  1037. X    {
  1038. X    endwin ();
  1039. X    fprintf (stderr, 
  1040. X         "%s: Terminal ('%s') too small (need %d cols, have %d)\n\n", 
  1041. X         prognm, ttytype, MNCOLS, COLS);
  1042. X    exit (1);
  1043. X    }
  1044. X
  1045. X    if (compute_window_sizes() == -1)
  1046. X    {
  1047. X    endwin();            /* error printed in compute_.. */
  1048. X    exit(1);
  1049. X    }
  1050. X
  1051. X    bzero(&aw, sizeof(aw));
  1052. X    aw.wmain = newwin (0,0,0,0);        /* Create main window    */
  1053. X    create_sub_windows (aw.wmain) ;        /* create all sub-wins    */
  1054. X
  1055. X    scrollok (aw.wmain, TRUE);            /* Allow scrolling    */
  1056. X    leaveok (aw.wmain, FALSE);            /* leave cursor at curxy */
  1057. X
  1058. X}                        /* end: setup_display()    */
  1059. X
  1060. X/*+         compute_window_sizes
  1061. X** FUNCTION:
  1062. X**     Calculates the sizes of the various variable windows like the
  1063. X** EVENT window and then the corresponding size of the message window.
  1064. X** The minimum size of the event window is 2 rows and the maximum
  1065. X** size is LINES - (sum of all fixed sized windows). It returns a -1
  1066. X** if the size of the screen is too small. Minimum message window size
  1067. X** is 1 line (this is added to the fixedsz and then added to the msg
  1068. X** window size. Thus, the minimum window size is fixedsz + min(event sz)
  1069. X**
  1070. X**/
  1071. Xcompute_window_sizes()
  1072. X{
  1073. X    extern int titlesz, hdrsz, promptsz, 
  1074. X           eventsz, msgtitlesz, msgsz, LINES ;    /* In netmon.c        */
  1075. X    int fixedsz ;                /* total fixed win size    */
  1076. X
  1077. X    titlesz = TITLESZ;                /* Fixed window sizes    */
  1078. X    hdrsz   = HDRSZ ;                /* Fixed  ..        */
  1079. X    promptsz = PROMPTSZ ;            /* Fixed ..        */
  1080. X    msgtitlesz = MSGTITLESZ ;            /* Fixed ..        */
  1081. X
  1082. X    fixedsz = titlesz + hdrsz + promptsz + msgtitlesz + 1 ;
  1083. X
  1084. X    if (eventsz <= 0)                /* first time setting    */
  1085. X      eventsz = EVENTSZ ;
  1086. X
  1087. X    if (eventsz > (LINES - fixedsz))        /* Now verify size    */
  1088. X      eventsz = LINES - fixedsz ;        /* Maximum size        */
  1089. X    else if (eventsz < 2)
  1090. X      eventsz = 2;                /* minimum size        */
  1091. X
  1092. X    msgsz = LINES - fixedsz - eventsz + 1 ;    /* all remaining lines    */
  1093. X    
  1094. X    if (msgsz < 1)                /* msg win atleast 1     */
  1095. X    {
  1096. X    fprintf(stderr, "window_sizes: Lines lesser than %d\n", 
  1097. X        fixedsz + eventsz);
  1098. X    return (-1);                /* screen too small    */
  1099. X    }
  1100. X    return (0);
  1101. X}                    /* end: compute_win_sizes    */
  1102. X
  1103. X
  1104. X/*+         create_sub_windows
  1105. X** 
  1106. X** FUNCTION
  1107. X**
  1108. X** This function creates subwindows within the main window. The main
  1109. X** window is passed as a parameter to the module. The reason behind
  1110. X** creating sub-windows is that the sub-windows alter the main window
  1111. X** also and after making all the alterations, we need call only one
  1112. X** refresh to display all the changes.
  1113. X** 
  1114. X** The idea behind creating many windows instead of working with just
  1115. X** one is that each window represents a header, title, etc. and we can
  1116. X** manipulate the screen better.
  1117. X**
  1118. X** The location and number of the windows are found from the definition of
  1119. X** the 'allwins' structure and the '..SZ' definitions in the netmon.h
  1120. X** header file.
  1121. X**/
  1122. X
  1123. Xcreate_sub_windows (wmain)
  1124. X     WINDOW *wmain ;                /* Main window (parent)    */
  1125. X{
  1126. X    extern int COLS;
  1127. X    extern struct allwins aw ;            /* defined in netmon.h    */
  1128. X
  1129. X    aw.wtitle = subwin (wmain, titlesz, COLS, 0, 0) ;
  1130. X    aw.whdr   = subwin (wmain, hdrsz, COLS, titlesz, 0) ;
  1131. X    aw.wevent = subwin (wmain, eventsz, COLS, titlesz + hdrsz, 0);
  1132. X    aw.wmsgtitle = subwin (wmain, msgtitlesz, COLS, titlesz+hdrsz+eventsz, 0);
  1133. X    aw.wmsg = subwin (wmain, msgsz, COLS, titlesz+hdrsz+eventsz+msgtitlesz, 0);
  1134. X    aw.wprompt = subwin(wmain,promptsz,COLS, 
  1135. X            titlesz+hdrsz+eventsz+msgtitlesz+msgsz, 0);
  1136. X
  1137. X    scrollok (aw.wmsg, TRUE);        /* Message window can scroll    */
  1138. X    return (1);
  1139. X}                    /* end:  create_sub_windows()    */
  1140. X
  1141. END_OF_FILE
  1142.   if test 4602 -ne `wc -c <'nocol-3.0/src/netmon/setup_display.c'`; then
  1143.     echo shar: \"'nocol-3.0/src/netmon/setup_display.c'\" unpacked with wrong size!
  1144.   fi
  1145.   # end of 'nocol-3.0/src/netmon/setup_display.c'
  1146. fi
  1147. if test -f 'nocol-3.0/src/nsmon/nsmon.c' -a "${1}" != "-c" ; then 
  1148.   echo shar: Will not clobber existing file \"'nocol-3.0/src/nsmon/nsmon.c'\"
  1149. else
  1150.   echo shar: Extracting \"'nocol-3.0/src/nsmon/nsmon.c'\" \(5107 characters\)
  1151.   sed "s/^X//" >'nocol-3.0/src/nsmon/nsmon.c' <<'END_OF_FILE'
  1152. X/*
  1153. X * $Header: /home/aggarwal/lsrc/nocol/src/nsmon/RCS/nsmon.c,v 1.5 1993/11/03 20:51:03 aggarwal Exp $
  1154. X */
  1155. X/*+ 
  1156. X** FUNCTION:
  1157. X**     Make a domain nameserver query and send it off to the server.
  1158. X** Used as part of the 'nocol' nsmon nameserver monitoring program.
  1159. X** Query options customized to test if the nameserver is up and running.
  1160. X**
  1161. X**
  1162. X** AUTHOR
  1163. X**    S. Spencer Sun, Princeton Univ. / JvNCnet, June 1992
  1164. X**/
  1165. X
  1166. X/* Copyright 1993 JvNCnet, Global Enterprise Services */
  1167. X
  1168. X/*
  1169. X * $Log: nsmon.c,v $
  1170. X * Revision 1.5  1993/11/03  20:51:03  aggarwal
  1171. X * Added ifdef for h_addr (defined in netdb.h) in case its defined.
  1172. X *
  1173. X * Revision 1.4  1993/10/30  03:41:25  aggarwal
  1174. X * *** empty log message ***
  1175. X *
  1176. X * Revision 1.3  1993/10/29  23:15:25  aggarwal
  1177. X * Changed to use UDP instead of TCP. The timeout mechanism in
  1178. X * TCP was kinda ugly (using setjmp)
  1179. X *
  1180. X * Revision 1.2  1993/10/29  22:04:39  aggarwal
  1181. X * Cleaned up. Also set the setjmp env parameter to diff from
  1182. X * the one in main().
  1183. X *
  1184. X * Revision 1.1  1992/06/11  05:03:14  aggarwal
  1185. X * Initial revision
  1186. X *
  1187. X */
  1188. X
  1189. X
  1190. X#include <stdio.h>
  1191. X#include <netdb.h>
  1192. X#include <sys/types.h>
  1193. X#include <sys/socket.h>
  1194. X#include <sys/param.h>
  1195. X#include <netinet/in.h>
  1196. X#include <arpa/nameser.h>
  1197. X#include <resolv.h>        /* definition of 'state' */
  1198. X
  1199. X#include "nsmon.h"
  1200. X
  1201. Xstatic int n_debug ;        /* debugging within this module */
  1202. X
  1203. Xstatic char *rcode_bindings[] = {
  1204. X  "NOERROR",        /* 0 */
  1205. X  "FORMERR",        /* 1 */
  1206. X  "SERVFAIL",        /* 2 */
  1207. X  "NXDOMAIN",        /* 3 */
  1208. X  "NOTIMP",        /* 4 */
  1209. X  "REFUSED",        /* 5 */
  1210. X  "<unknown rcode>",    /* 6 */
  1211. X  "<unknown rcode>",    /* 7 */
  1212. X  "<unknown rcode>",    /* 8 */
  1213. X  "<unknown rcode>",    /* 9 */
  1214. X  "<unknown rcode>",    /* A */
  1215. X  "<unknown rcode>",    /* B */
  1216. X  "<unknown rcode>",    /* C */
  1217. X  "<unknown rcode>",    /* D */
  1218. X  "<unknown rcode>",    /* E */
  1219. X  "NOCHANGE"        /* F */
  1220. X};
  1221. X
  1222. X/*
  1223. X * nsmon -- builds the query using res_mkquery() and then sends it using
  1224. X * res_send().  Calling parameters and return values are detailed in nsmon.h.
  1225. X */
  1226. X
  1227. Xnsmon (server, request, class, type, timeout, aa_only, debug)
  1228. X  char *server, *request;
  1229. X  int class, type, timeout, aa_only, debug;
  1230. X{
  1231. X  int n, ch;
  1232. X  HEADER *hp;
  1233. X  char buf[BUFSIZ], answer[BUFSIZ], *p;
  1234. X  struct sockaddr_in sa, *psin ;
  1235. X  extern struct state _res;        /* defined in resolv.conf ? */
  1236. X  
  1237. X  psin = &(_res.nsaddr) ;
  1238. X  /* insert server address into _res structure */
  1239. X  bzero(psin, sizeof (*psin));
  1240. X  psin->sin_family = AF_INET ;
  1241. X  psin->sin_port = htons(NAMESERVER_PORT);
  1242. X  if (isdigit (*server))
  1243. X    psin->sin_addr.s_addr = inet_addr(server);
  1244. X  else
  1245. X  {
  1246. X      struct hostent *hp ;    /* gethostbyname returns in_addr structures */
  1247. X      if ((hp = gethostbyname(server)) == NULL)
  1248. X      {
  1249. X      fprintf (stderr, "gethostbyname () failed for '%s'- ", server);
  1250. X      perror("nsmon");
  1251. X      return ERROR ;
  1252. X      }
  1253. X#ifdef h_addr        /* in netdb.h */
  1254. X      bcopy ((char *)hp->h_addr, (char *)&(psin->sin_addr), hp->h_length) ;
  1255. X#else
  1256. X      bcopy ((char *)hp->h_addr_list[0], (char *)&(psin->sin_addr), 
  1257. X         hp->h_length) ;
  1258. X#endif
  1259. X  }
  1260. X
  1261. X  if (debug) 
  1262. X    printf ("Nameserver is %s, port %d\n",
  1263. X      inet_ntoa(_res.nsaddr.sin_addr), ntohs(_res.nsaddr.sin_port));
  1264. X
  1265. X  /*
  1266. X   * set various flags for _res options
  1267. X   */
  1268. X  _res.options = RES_INIT;        /* don't call res_init() */
  1269. X/*  _res.options |= RES_USEVC ;        /* use TCP and not UDP */
  1270. X  _res.options |= RES_PRIMARY;        /* only query primary server */
  1271. X  _res.options &= ~RES_RECURSE ;    /* no recursion */
  1272. X  _res.options &= ~RES_DNSRCH ;        /* don't search parent, etc. */
  1273. X  if (aa_only)
  1274. X    _res.options |= RES_AAONLY;     /* only authoritative answers */
  1275. X  if (timeout)
  1276. X     _res.retrans = timeout ;        /* timeout in seconds */
  1277. X
  1278. X  if (debug > 1) {
  1279. X    _res.options |= RES_DEBUG;
  1280. X    fprintf(stderr, "     _res.options = %ld\n", _res.options);
  1281. X    fprintf(stderr, "     _res.defdname = %s\n", _res.defdname);
  1282. X    fprintf(stderr, "About to call res_mkquery()\n");
  1283. X  }
  1284. X
  1285. X  /* First ask res_mkquery() to build a query structure */
  1286. X  /* Types defined in nameser.h  T_A, T_NS, T_SOA, T_PTR */
  1287. X  n = res_mkquery(QUERY, request, class, type, 
  1288. X          (char *)NULL, 0, NULL, (char *)buf, sizeof(buf));
  1289. X  /* query in buf */
  1290. X  
  1291. X  if (n < 0) {
  1292. X      if (debug) {
  1293. X      fprintf(stderr, "nsmon: problem with site %s\n", server);
  1294. X      perror("res_mkquery");
  1295. X      }
  1296. X      return ERROR;
  1297. X  }
  1298. X
  1299. X  if (debug > 1) {
  1300. X      fprintf(stderr, "     _res.options = %ld\n", _res.options);
  1301. X      fprintf(stderr, "     _res.defdname = %s\n", _res.defdname);
  1302. X      fprintf(stderr, "About to call res_send()\n");
  1303. X  }
  1304. X
  1305. X  /* Now send the query using res_send() */
  1306. X
  1307. X  n = res_send(buf, n, answer, sizeof(answer) ) ;
  1308. X  
  1309. X  if (n < 0) {
  1310. X      if (debug) {
  1311. X      printf("nsmon: problem with site %s\n",  server);
  1312. X      perror("res_send");
  1313. X      }
  1314. X      return ERROR;
  1315. X  }
  1316. X  else
  1317. X    if (debug > 1)
  1318. X      fprintf (stderr, "nsmon: Returned from res_send\n");
  1319. X  
  1320. X  hp = (HEADER *)answer ;
  1321. X  
  1322. X  if (hp->rcode != NOERROR) {
  1323. X      if (debug)
  1324. X    fprintf(stderr, "got rcode of %s from nameserver\n",
  1325. X        rcode_bindings[hp->rcode]);
  1326. X      return ERROR;
  1327. X  }
  1328. X
  1329. X  if (aa_only && !(hp->aa))
  1330. X    return NOT_AUTHORITATIVE;
  1331. X  
  1332. X  return ALL_OK;        /* Don't check the response, must be okay */
  1333. X}            /* end nsmon() */
  1334. END_OF_FILE
  1335.   if test 5107 -ne `wc -c <'nocol-3.0/src/nsmon/nsmon.c'`; then
  1336.     echo shar: \"'nocol-3.0/src/nsmon/nsmon.c'\" unpacked with wrong size!
  1337.   fi
  1338.   # end of 'nocol-3.0/src/nsmon/nsmon.c'
  1339. fi
  1340. if test -f 'nocol-3.0/src/perlnocol/idlemodemmon' -a "${1}" != "-c" ; then 
  1341.   echo shar: Will not clobber existing file \"'nocol-3.0/src/perlnocol/idlemodemmon'\"
  1342. else
  1343.   echo shar: Extracting \"'nocol-3.0/src/perlnocol/idlemodemmon'\" \(5917 characters\)
  1344.   sed "s/^X//" >'nocol-3.0/src/perlnocol/idlemodemmon' <<'END_OF_FILE'
  1345. X#!/usr/local/bin/perl 
  1346. X# $Header$
  1347. X#
  1348. X#     idlemodemmon - perl monitor for flagging IDLE modem lines on 
  1349. X#            Cisco Terminal Servers
  1350. X#
  1351. X#  -Vikas Aggarwal, vikas@jvnc.net
  1352. X#
  1353. X#    Copyright 1993 JvNCnet, Global Enterprise Services
  1354. X#
  1355. X#  THIS IS AN SNMP based program and uses the CMU-SNMP 'snmpwalk' program.
  1356. X#
  1357. X# To Install:
  1358. X#
  1359. X#    Compile the CMU-SNMP programs and install snmpwalk and the
  1360. X#    mib.txt file in desired locations. Then set the variables
  1361. X#    as described in the 'Customize' section.
  1362. X#
  1363. X# Reads a list of cisco terminal servers to monitor (from
  1364. X# a config file) and thresholds. Flags idle lines via NOCOL.
  1365. X#
  1366. X#
  1367. X# Files used:
  1368. X#   snmpwalk -        From CMU-SNMP distribution
  1369. X#   mib.txt  -        MIB file in ASN syntax with merged Cisco MIB.
  1370. X#
  1371. X# Nocol event elements used:
  1372. X#   sender                     "idlemodemmon"
  1373. X#   severity                   as read from the config file
  1374. X#   site
  1375. X#    name                      the cisco name
  1376. X#    addr                      cisco IP address
  1377. X#   var                       
  1378. X#    name                      "ModemIdle"
  1379. X#    value                     1 means at Info level
  1380. X#    threshold                 as read from the config file
  1381. X#    units                     always "Secs"
  1382. X#
  1383. X## 
  1384. X##
  1385. X#
  1386. X############################
  1387. X## Variables customization #  overrides values in the nocollib.pl library
  1388. X############################
  1389. X$SNMP = "../cmu-snmp" ;            # To find binary and MIBFILW
  1390. X$prog =  "$SNMP/bin/snmpwalk" ;        # location of 'snmpwalk'
  1391. X$mibfile = "$SNMP/mib.txt" ;    # Location of MIB file
  1392. X
  1393. X# Cisco MIB ASN
  1394. X# cisco.local...tsLineActive = 9.2.9.2.1.1
  1395. X$mibcisco  = ".iso.org.dod.internet.private.enterprises.cisco.local" ;
  1396. X$miblineidle = $mibcisco.".lts.ltsLineSessionTable.ltsLineSessionEntry.tslineSesIdle" ;
  1397. X$community=  "public";
  1398. X
  1399. X$varname="ModemIdle";
  1400. X$varunits="Secs" ;            # the var.units field in EVENT struct
  1401. X$sleepint=60*10;                   # Seconds to sleep between tries.
  1402. X############################
  1403. X$debug = 1;                # set to 1 for debugging output
  1404. X$libdebug = 0;                # set to 1 for debugging output
  1405. X
  1406. Xrequire  "nocollib.pl" ;
  1407. X
  1408. X-x $prog || die("Could not find executable $prog, exiting");
  1409. X-f $mibfile || die("Could not find MIB file $rprog, exiting");
  1410. X$ENV{"MIBFILE"}= $mibfile ;
  1411. X
  1412. X@me=split(/\//,$0); $me=pop(@me);
  1413. X#$piddir=join("/",@me); if ($piddir eq "") {$piddir=$etcdir;}
  1414. X$piddir=$etcdir;
  1415. X$cfile="$etcdir/$me-confg";
  1416. X$datafile="$datadir/$me-output";
  1417. X
  1418. X$sender= $me ;                # filled in the EVENT sender
  1419. X
  1420. X
  1421. X##
  1422. X# Read the config file. Use '\t' as a separator for 'item'
  1423. Xsub readconf {
  1424. X    local ($nets, $interface, $zone) ;
  1425. X
  1426. X    open(CONFIG,"<$cfile")||die("Couldn't find $cfile, exiting");
  1427. X    while(<CONFIG>)
  1428. X    {
  1429. X    chop;
  1430. X    if(/^\s*#/) {next;}   # skip comments
  1431. X    if(/^\s*$/) {next;}   # skip blank lines
  1432. X    if (/\s*(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s*$/)
  1433. X    {
  1434. X        $item="$1\t$2" ;     # the name and address
  1435. X        $wlevel{$item} = $3; # Warning level
  1436. X        $elevel{$item} = $4; # Error level
  1437. X        $clevel{$item} = $5; # Critical level
  1438. X        push(@items,$item);
  1439. X    }
  1440. X    else {print "Ignoring illegal line: $_\n";}
  1441. X
  1442. X    }    # end while(CONFIG)
  1443. X
  1444. X    close(CONFIG);
  1445. X    if(0>$#items){die("Nothing to monitor in $cfile, exiting")};
  1446. X    if ($debug) {
  1447. X    print "Items are:\n"; foreach (@items) { print "\t$_\n" } ;
  1448. X    }
  1449. X}                # end: readconf
  1450. X
  1451. X
  1452. X# 
  1453. X## Check state of each router
  1454. X##
  1455. X#
  1456. X# Walks the TServer ltsLineActive/ltsLineType  mib trees (cisco specific) 
  1457. X# and collects TERMINAL type lines that are ACTIVE.
  1458. X# Prints number of active lines and total number of TTY lines.
  1459. X# Prints '-1' on error.
  1460. X#
  1461. X# CAVEATS:
  1462. X#   - Walking entire mib tree over UDP can be iffy. This is tested by seeing
  1463. X#     if any responses are missing in the TYPE list and the ACTIVE list.
  1464. X#
  1465. X###    
  1466. X#
  1467. Xsub dotest {
  1468. X    local ($router) = @_ ;
  1469. X    local ($maxidle) = -1 ;
  1470. X    local ($walkidle); 
  1471. X
  1472. X    if ($debug) { print "Checking $router\n"; }
  1473. X
  1474. X    -x $prog || die("Could not find executable $prog, exiting");
  1475. X
  1476. X    $walkidle = "$prog $router $community $miblineidle";
  1477. X#
  1478. X# Output of Check-active SNMP command is:
  1479. X#    Name: .iso.org.dod........lts.ltsLineSessionEntry.tslineSesIdle.2.1
  1480. X#    INTEGER: 1
  1481. X
  1482. X    open (ACTIVE, "$walkidle |") || die "Can't check active lines.";
  1483. X    while(<ACTIVE>){
  1484. X    chop;
  1485. X    if (/^\s*INTEGER:\s*(\d+)\s*$/)
  1486. X    {
  1487. X        if ($1 > $maxidle) { $maxidle = $1 ; }
  1488. X        if ($debug) { print "$1 secs, "; }
  1489. X    }
  1490. X    }
  1491. X    close(ACTIVE);
  1492. X
  1493. X    if ($debug) {print "(debug) Max idle line= $maxidle\n"; }
  1494. X
  1495. X    return ($maxidle) ;
  1496. X
  1497. X}    # end &dotest()
  1498. X
  1499. X
  1500. X###
  1501. X### main
  1502. X###
  1503. X
  1504. X# Fork and get rid of old process.
  1505. Xif($p=fork){print "$p\n";exit;}
  1506. X&standalone($me,$piddir);
  1507. X
  1508. X&readconf ;
  1509. X
  1510. Xforeach $item (@items) {
  1511. X    local ($host, $addr) = split( /\t/, $item );
  1512. X    &init_event ($host, $addr, $item);
  1513. X}
  1514. X
  1515. Xwhile (1)
  1516. X{
  1517. X    foreach $item (@items) {
  1518. X    local ($host, $addr) = split( /\t/, $item );
  1519. X    local ($lineidle) =  &dotest ($addr);
  1520. X
  1521. X    if ($lineidle < 0)
  1522. X    {
  1523. X        print "$me: dotest failed for $host ($addr) , skipping\n";
  1524. X        next ;
  1525. X    }
  1526. X    if ($lineidle >= $clevel{$item} ) # critical level
  1527. X    {
  1528. X        if ($debug) {print "(debug): Maxlevel is Critical\n";}
  1529. X        $varthres{$item} = $clevel{$item} ; # threshold
  1530. X        &update_event($item, 0, $lineidle, $E_CRITICAL);
  1531. X    }
  1532. X    elsif ($lineidle >= $elevel{$item} )
  1533. X    {
  1534. X        if ($debug) {print "(debug): Maxlevel is Error\n";}
  1535. X        $varthres{$item} = $elevel{$item} ; # threshold
  1536. X        &update_event($item, 0, $lineidle, $E_ERROR);
  1537. X    }
  1538. X    elsif ($lineidle >= $wlevel{$item} )
  1539. X    {
  1540. X        if ($debug) {print "(debug): Maxlevel is Warning\n";}
  1541. X        $varthres{$item} = $wlevel{$item} ; # threshold
  1542. X        &update_event($item, 0, $lineidle, $E_WARNING);
  1543. X    }
  1544. X    else
  1545. X    {
  1546. X        if ($debug) {print "(debug): Level is INFO\n";}
  1547. X        $varthres{$item} = $wlevel{$item} ; # threshold is warning level
  1548. X        &update_event($item, 1, $lineidle, $E_WARNING); # status UP
  1549. X    }    
  1550. X    }
  1551. X
  1552. X    ; ## Note: we want to write the file quickly.
  1553. X
  1554. X    open(OEVENTS,">$datafile");
  1555. X    foreach $item (@items) {
  1556. X    &writeevent($item);
  1557. X    }
  1558. X    close(OEVENTS);
  1559. X    sleep($sleepint);
  1560. X}
  1561. X
  1562. END_OF_FILE
  1563.   if test 5917 -ne `wc -c <'nocol-3.0/src/perlnocol/idlemodemmon'`; then
  1564.     echo shar: \"'nocol-3.0/src/perlnocol/idlemodemmon'\" unpacked with wrong size!
  1565.   fi
  1566.   chmod +x 'nocol-3.0/src/perlnocol/idlemodemmon'
  1567.   # end of 'nocol-3.0/src/perlnocol/idlemodemmon'
  1568. fi
  1569. if test -f 'nocol-3.0/src/perlnocol/modemmon' -a "${1}" != "-c" ; then 
  1570.   echo shar: Will not clobber existing file \"'nocol-3.0/src/perlnocol/modemmon'\"
  1571. else
  1572.   echo shar: Extracting \"'nocol-3.0/src/perlnocol/modemmon'\" \(5111 characters\)
  1573.   sed "s/^X//" >'nocol-3.0/src/perlnocol/modemmon' <<'END_OF_FILE'
  1574. X#!/usr/local/bin/perl 
  1575. X
  1576. X# $Header: /home/aggarwal/lsrc/nocol/src/perlnocol/RCS/modemmon,v 1.1 1993/10/30 04:05:07 aggarwal Exp $
  1577. X#
  1578. X#        modemmon - perl monitor for modem line's usage on cisco's
  1579. X#
  1580. X#  Vikas Aggarwal,  vikas@jvnc.net
  1581. X#
  1582. X#    Copyright 1993 JvNCnet, Global Enterprise Services
  1583. X#
  1584. X# Modemmon  reads a list of cisco terminal servers to monitor (from
  1585. X# a config file) and thresholds. It then logs into the cisco's and
  1586. X# counts the number of lines in use. When the used lines exceeds the
  1587. X# thresholds, the lines are displayed in NOCOL data format.
  1588. X# Requires the 'rcisco' program for logging into the cisco specified.
  1589. X#
  1590. X# Nocol event elements used:
  1591. X#   sender                     "modemmon"
  1592. X#   severity                   as read from the config file
  1593. X#   site
  1594. X#    name                      the cisco name
  1595. X#    addr                      cisco IP address
  1596. X#   var                       
  1597. X#    name                      "ModemLines"
  1598. X#    value                     1 means at Info level
  1599. X#    threshold                 as read from the config file
  1600. X#    units                     always "Usage"
  1601. X#
  1602. X## 
  1603. X##
  1604. X#
  1605. X#
  1606. X############################
  1607. X## Variables customization #  overrides values in the nocollib.pl library
  1608. X############################
  1609. X$rprog="rcisco";            # Path for rcisco.
  1610. X$rpasswd="";                # if NULL, uses the default in rcisco
  1611. X$rcommand="who";
  1612. X$varname="ModemLines";
  1613. X$varunits="Usage" ;            # the var.units field in EVENT struct
  1614. X$sleepint=60*5;                   # Seconds to sleep between tries.
  1615. X############################
  1616. X$debug = 0;                # set to 1 for debugging output
  1617. X$libdebug = 0;                # set to 1 for debugging output
  1618. X
  1619. Xrequire  "nocollib.pl" ;
  1620. X
  1621. X-x $rprog || die("Could not find executable $rprog, exiting");
  1622. X
  1623. X@me=split(/\//,$0); $me=pop(@me);
  1624. X#$piddir=join("/",@me); if ($piddir eq "") {$piddir=$etcdir;}
  1625. X$piddir=$etcdir;
  1626. X$cfile="$etcdir/$me-confg";
  1627. X$datafile="$datadir/$me-output";
  1628. X
  1629. X$sender= $me ;                # filled in the EVENT sender
  1630. X
  1631. X
  1632. X##
  1633. X# Read the config file. Use '\t' as a separator for 'item'
  1634. Xsub readconf {
  1635. X    local ($nets, $interface, $zone) ;
  1636. X
  1637. X    open(CONFIG,"<$cfile")||die("Couldn't find $cfile, exiting");
  1638. X    while(<CONFIG>)
  1639. X    {
  1640. X    chop;
  1641. X    if(/^\s*#/) {next;}   # skip comments
  1642. X    if(/^\s*$/) {next;}   # skip blank lines
  1643. X    if (/\s*(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s*$/)
  1644. X    {
  1645. X        $item="$1\t$2" ;     # the name and address
  1646. X        $wlevel{$item} = $3; # Warning level
  1647. X        $elevel{$item} = $4; # Error level
  1648. X        $clevel{$item} = $5; # Critical level
  1649. X        push(@items,$item);
  1650. X    }
  1651. X    else {print "Ignoring illegal line: $_\n";}
  1652. X
  1653. X    }    # end while(CONFIG)
  1654. X
  1655. X    close(CONFIG);
  1656. X    if(0>$#items){die("Nothing to monitor in $cfile, exiting")};
  1657. X    if ($debug) {
  1658. X    print "Items are:\n"; foreach (@items) { print "\t$_\n" } ;
  1659. X    }
  1660. X}                # end: readconf
  1661. X
  1662. X## Check state of each router
  1663. X#
  1664. Xsub dotest {
  1665. X    local ($router) = @_ ;
  1666. X    local ($nusers) = 0;
  1667. X    local ($loginok) = 0;
  1668. X
  1669. X    if ($debug) { print "Checking $router\n"; }
  1670. X    $command="$rprog $router ".' "'."$rpasswd".'" '.'"'."$rcommand".'"';
  1671. X    if ($debug) {print "(debug) dotest: running command $command\n" ;}
  1672. X
  1673. X    open (ROUTER, "$command|") ;
  1674. X    
  1675. X    while(<ROUTER>) {
  1676. X    tr/\r\n//d;
  1677. X    if ( />/ ) {$loginok = 1 ;} # got the 'Router>' prompt
  1678. X    if ( /Dial-in/ )  {$nusers += 1 ;}
  1679. X    elsif ($debug) {
  1680. X#        print "(debug) skipping line: $_\n" ;
  1681. X    }
  1682. X    }  # end while
  1683. X    close (ROUTER);
  1684. X#    sleep 5 ;            # process needs to die off ??
  1685. X
  1686. X    if ($loginok == 0) { 
  1687. X    print "Login into remote host failed\n" ;
  1688. X    $nusers = -1 ;
  1689. X    }
  1690. X    if ($debug) {print "Number of users= $nusers\n" ;}
  1691. X    return ($nusers) ;        # not caring about timeouts
  1692. X
  1693. X} # end: dotest()
  1694. X
  1695. X
  1696. X
  1697. X###
  1698. X### main
  1699. X###
  1700. X
  1701. X# Fork and get rid of old process.
  1702. Xif($p=fork){print "$p\n";exit;}
  1703. X&standalone($me,$piddir);
  1704. X
  1705. X&readconf ;
  1706. X
  1707. Xforeach $item (@items) {
  1708. X    local ($host, $addr) = split( /\t/, $item );
  1709. X    &init_event ($host, $addr, $item);
  1710. X}
  1711. X
  1712. Xwhile (1)
  1713. X{
  1714. X    foreach $item (@items) {
  1715. X    local ($host, $addr) = split( /\t/, $item );
  1716. X    local ($linesused) =  &dotest ($addr);
  1717. X
  1718. X    if ($linesused < 0)
  1719. X    {
  1720. X        print "$me: dotest failed for $host ($addr) , skipping\n";
  1721. X        next ;
  1722. X    }
  1723. X    if ($linesused >= $clevel{$item} ) # critical level
  1724. X    {
  1725. X        if ($debug) {print "(debug): Maxlevel is Critical\n";}
  1726. X        $varthres{$item} = $clevel{$item} ; # threshold
  1727. X        &update_event($item, 0, $linesused, $E_CRITICAL);
  1728. X    }
  1729. X    elsif ($linesused >= $elevel{$item} )
  1730. X    {
  1731. X        if ($debug) {print "(debug): Maxlevel is Error\n";}
  1732. X        $varthres{$item} = $elevel{$item} ; # threshold
  1733. X        &update_event($item, 0, $linesused, $E_ERROR);
  1734. X    }
  1735. X    elsif ($linesused >= $wlevel{$item} )
  1736. X    {
  1737. X        if ($debug) {print "(debug): Maxlevel is Warning\n";}
  1738. X        $varthres{$item} = $wlevel{$item} ; # threshold
  1739. X        &update_event($item, 0, $linesused, $E_WARNING);
  1740. X    }
  1741. X    else
  1742. X    {
  1743. X        if ($debug) {print "(debug): Level is INFO\n";}
  1744. X        $varthres{$item} = $wlevel{$item} ; # threshold is warning level
  1745. X        &update_event($item, 1, $linesused, $E_WARNING); # status UP
  1746. X    }    
  1747. X    }
  1748. X
  1749. X    ; ## Note: we want to write the file quickly.
  1750. X
  1751. X    open(OEVENTS,">$datafile");
  1752. X    foreach $item (@items) {
  1753. X    &writeevent($item);
  1754. X    }
  1755. X    close(OEVENTS);
  1756. X    sleep($sleepint);
  1757. X}
  1758. X
  1759. END_OF_FILE
  1760.   if test 5111 -ne `wc -c <'nocol-3.0/src/perlnocol/modemmon'`; then
  1761.     echo shar: \"'nocol-3.0/src/perlnocol/modemmon'\" unpacked with wrong size!
  1762.   fi
  1763.   chmod +x 'nocol-3.0/src/perlnocol/modemmon'
  1764.   # end of 'nocol-3.0/src/perlnocol/modemmon'
  1765. fi
  1766. if test -f 'nocol-3.0/src/perlnocol/novellmon' -a "${1}" != "-c" ; then 
  1767.   echo shar: Will not clobber existing file \"'nocol-3.0/src/perlnocol/novellmon'\"
  1768. else
  1769.   echo shar: Extracting \"'nocol-3.0/src/perlnocol/novellmon'\" \(5881 characters\)
  1770.   sed "s/^X//" >'nocol-3.0/src/perlnocol/novellmon' <<'END_OF_FILE'
  1771. X#!/usr/local/bin/perl
  1772. X#
  1773. X# $Header: /home/aggarwal/lsrc/nocol/src/perlnocol/RCS/novellmon,v 1.3 1993/10/28 17:42:45 aggarwal Exp $
  1774. X#
  1775. X#    novellmon - perl nocol Novell service monitor
  1776. X#
  1777. X# Date: September 21, 1993
  1778. X# Programmer: John Wobus, jmwobus@mailbox.syr.edu
  1779. X#  Modifications:  vikas@jvnc.net
  1780. X#
  1781. X#    (c) Syracuse University Computing & Network Services 1993
  1782. X#
  1783. X# No warranty is expressed or implied.  Permission to copy and use is
  1784. X# extended to all.  Permission to redistribute is granted under the
  1785. X# following conditions: it is not sold for profit; this copyright
  1786. X# notice remains intact; the same permissions extend to the recipient;
  1787. X# and if any changes are made, a notice is added so stating.
  1788. X#
  1789. X# Command Format:
  1790. X#
  1791. X#  novellmon
  1792. X#
  1793. X#    Automatically kills old process and forks a new one, reading
  1794. X#    the configuration file in the process.
  1795. X#
  1796. X# What it does:
  1797. X#
  1798. X#    novellmon reads the list of Novell servers from a Cisco router and
  1799. X#    checks for the appearance of the services listed in its own
  1800. X#    configuration file and reports any that are missing.  Example:
  1801. X#
  1802. X#    Site      Address      Time   +-Variable-+ +-Value-+  Condition
  1803. X#    DINAH  4(files)        09:58    IPX server        0    Critical
  1804. X#
  1805. X#    This line states that a file server called DINAH is not available.
  1806. X#
  1807. X# Files used:
  1808. X#
  1809. X#   rcisco                      perl program to do a Cisco router
  1810. X#                               command remotely.
  1811. X#   nocol/data/novellmon-output path to which to write nocol events.
  1812. X#   novellmon-confg             configuration file.
  1813. X#   novellmon.pid               file holding novellmon's current process id.
  1814. X#
  1815. X# Nocol event elements used:
  1816. X#   sender                     "novellmon"
  1817. X#   mon, day, hour, min        time at which entity went up or down
  1818. X#   severity                   up: 4; down: 3,2,1; test & down: 2;
  1819. X#   nocop                      up, down, unknown
  1820. X#   site
  1821. X#    name                      the Server name
  1822. X#    addr                      the numerical type of service and an
  1823. X#                               interpretation in parenthesis, e.g.
  1824. X#                               "4(files)" for file service.
  1825. X#   var                       
  1826. X#    name                      "IPX server"
  1827. X#    value                     1 means up, 0 means down
  1828. X#    threshold                 always 2
  1829. X#    units                     always "entry"
  1830. X#
  1831. X# To install this:
  1832. X#   (1) Choose where to put this file and the above 4 files and
  1833. X#       assign the perl variables below appropriately.
  1834. X#   (2) Create your novellmon-confg file in its chosen place.
  1835. X#   (3) Edit rcisco to include your Cisco router's password and put
  1836. X#       rcisco in its chosen place.
  1837. X#   (4) Put this file in its chosen place.
  1838. X#   (5) Add appropriate code to rc.local to start this monitor.
  1839. X#
  1840. X# Configuration file format:
  1841. X#    #<text>                                   Comment line.
  1842. X#    router=<router>                           Name of Cisco router.
  1843. X#    <servername> <servicetype>                IPX service, name & numerical
  1844. X#                                               type.
  1845. X#
  1846. X# Sample configuration file:
  1847. X#    # novellmon configuration
  1848. X#    router=mycisco.excellent.edu
  1849. X#    DINAH   4
  1850. X#
  1851. X## 
  1852. X##
  1853. X#
  1854. X#
  1855. X############################
  1856. X## Variables customization #  overrides values in the nocollib.pl library
  1857. X############################
  1858. X$rprog="./rcisco";        # Path for rcisco.
  1859. X$rpasswd="";            # if NULL, uses the default in rcisco
  1860. X$rcommand="show novell servers";
  1861. X$varname="IPX_server";        # Registered appletalk route
  1862. X$varunits="Entry" ;        # the var.units field in EVENT structure
  1863. X$sleepint=60*5;            # Seconds to sleep between tries.
  1864. X############################
  1865. X$debug = 0;            # set to 1 for debugging output
  1866. X$libdebug = 0;            # set to 1 for library debug output
  1867. X
  1868. Xrequire  "nocollib.pl" ;
  1869. X
  1870. X-x $rprog || die("Could not find executable $rprog, exiting");
  1871. X
  1872. X@me=split(/\//,$0); $me=pop(@me);
  1873. X#$piddir=join("/",@me); if ($piddir eq "") {$piddir=$etcdir;}
  1874. X$piddir=$etcdir;
  1875. X$cfile="$etcdir/$me-confg";
  1876. X$datafile="$datadir/$me-output";
  1877. X
  1878. X$sender= $me ;                # filled in the EVENT sender
  1879. X$maxseverity = $E_ERROR ;        # max severity of events
  1880. X
  1881. X%tname=("4","files","47","printing","10C","net3270","7050","ipxbootp");
  1882. X
  1883. X##
  1884. X# Read the config file. Use '\t' as a separator.
  1885. X#
  1886. Xsub readconf {
  1887. X    open(CONFIG,"<$cfile")||die("Couldn't find $cfile, exiting");
  1888. X    while(<CONFIG>){
  1889. X    chop;
  1890. X    if(/^\s*#/) {next;}   # skip comments
  1891. X    if(/^\s*$/) {next;}   # skip blank lines
  1892. X    if(/^\s*router\s*=\s*(\S+)(\s.*)?$/) {$router=$1;}
  1893. X    elsif(/^\s*(\S+)\s+(\S+)(\s.*)?$/) {push(@items,"$1\t$2");}
  1894. X    }
  1895. X    close(CONFIG);
  1896. X    if(!$router){die("No router specified in $cfile, exiting")};
  1897. X    if(0>$#items){die("Nothing to monitor in $cfile, exiting")};
  1898. X}
  1899. X
  1900. X
  1901. X## Check the current state of the router
  1902. X#
  1903. Xsub dotest {
  1904. X    local($loginok) = 0 ;
  1905. X    foreach(@items){$found{$_}=0;}
  1906. X
  1907. X    $command="$rprog $router ".' "'."$rpasswd".'" '.'"'."$rcommand".'"';
  1908. X    open(ROUTER,"$command|");
  1909. X
  1910. X    while(<ROUTER>){
  1911. X    tr/\r\n//d;
  1912. X    if ( />/ ) {$loginok = 1 ;} # got the 'Router>' prompt
  1913. X    if(/^\s*(\S+)\s+(\S+)\s+(\S+)\s+(\d+)\s+(\S+)$/) {
  1914. X        $type=$1; $name=$2; $addr=$3; $hops=$4; $interface=$5;
  1915. X        $item="$name\t$type";
  1916. X        $found{$item}=1;
  1917. X    }
  1918. X    }
  1919. X    close(ROUTER);
  1920. X    if ($loginok == 0) { print "Login into remote host failed\n" ;}
  1921. X}
  1922. X
  1923. X
  1924. X###
  1925. X### Main program:
  1926. X###
  1927. X
  1928. X#Fork and get rid of old process.
  1929. X
  1930. Xif($p=fork){print "$p\n";exit;}
  1931. X&standalone($me,$piddir);
  1932. X
  1933. X&readconf;
  1934. X
  1935. Xforeach $item (@items) {
  1936. X    local($name,$type)=split(/\t/,$item);
  1937. X    &init_event("$name", "$type(".$tname{$type}.")", $item);
  1938. X}
  1939. X
  1940. X
  1941. Xwhile (1)
  1942. X{
  1943. X    &dotest;
  1944. X    foreach $item (@items)
  1945. X    {
  1946. X    if ($found{$item}) { &update_event($item, 1, 1, $maxseverity); }
  1947. X    else { &update_event($item, 0, 0, $maxseverity); }
  1948. X    }
  1949. X    #Note: we want to write the file quickly.
  1950. X    open(OEVENTS,">$datafile");
  1951. X    foreach $item (@items)
  1952. X    {
  1953. X    &writeevent($item);
  1954. X    }
  1955. X    close(OEVENTS);
  1956. X    sleep($sleepint);
  1957. X}
  1958. END_OF_FILE
  1959.   if test 5881 -ne `wc -c <'nocol-3.0/src/perlnocol/novellmon'`; then
  1960.     echo shar: \"'nocol-3.0/src/perlnocol/novellmon'\" unpacked with wrong size!
  1961.   fi
  1962.   chmod +x 'nocol-3.0/src/perlnocol/novellmon'
  1963.   # end of 'nocol-3.0/src/perlnocol/novellmon'
  1964. fi
  1965. if test -f 'nocol-3.0/src/pingmon/Makefile' -a "${1}" != "-c" ; then 
  1966.   echo shar: Will not clobber existing file \"'nocol-3.0/src/pingmon/Makefile'\"
  1967. else
  1968.   echo shar: Extracting \"'nocol-3.0/src/pingmon/Makefile'\" \(3543 characters\)
  1969.   sed "s/^X//" >'nocol-3.0/src/pingmon/Makefile' <<'END_OF_FILE'
  1970. X# $Id: Makefile,v 1.12 1993/10/30 03:12:52 aggarwal Exp $
  1971. X#
  1972. X# Makefile for 'pingmon'
  1973. X#
  1974. X# This file is pretty complicated because the same objects create OSIpingmon
  1975. X# as well as IPpingmon. Only the compile time definitions are different.
  1976. X# One way was to have two separate Makefile's but passing the definitions
  1977. X# between three layers of 'make' is kinda hairy (3 layers since invoked from
  1978. X# the main 'nocol' makefile).
  1979. X#
  1980. X# Anyway, you can do the following:
  1981. X#
  1982. X#     make PROTOCOL=IP
  1983. X#    make PROTOCOL=OSI
  1984. X#
  1985. X## SET THIS
  1986. X# Directories needed by the Makefile
  1987. XTOP =           /usr/nocol
  1988. XSRCDIR =    $(TOP)/src
  1989. X
  1990. XBINDIR =        $(TOP)/bin
  1991. XETCDIR =        $(TOP)/etc
  1992. XINCLUDEDIR =    $(SRCDIR)/include
  1993. XLIBDIR =    $(SRCDIR)/lib
  1994. X
  1995. X## SET THIS
  1996. X# Directories needed by the program.
  1997. X#     DATADIR            for creating the PING-OUTPUT
  1998. X#    IPNODESFILE        location of IP nodes/hosts file
  1999. X#    IPPING            location of the IP ping program
  2000. X#    OSINODESFILE        location of the OSI nodes/hosts file
  2001. XDATADIR =       $(TOP)/data
  2002. X
  2003. XIPNODESFILE =    $(ETCDIR)/ipnodes
  2004. XIPPING =    /usr/etc/ping
  2005. X
  2006. XOSINODESFILE =    $(ETCDIR)/osinodes
  2007. XOSIPING =    /usr/sunlink/bin/osiping
  2008. X
  2009. X## Default protocol is IP Set to OSI for OSIpingmon.
  2010. XPROTOCOL =     IP
  2011. X
  2012. X## SET THIS
  2013. X# Set the various defines for compile time defines:
  2014. X#     -DMULTIPING    if using IPPING = 'multiping'
  2015. X#
  2016. XSYSDEFS =    # -DMULTIPING
  2017. X
  2018. X####
  2019. X#### Can leave the rest alone #######
  2020. X####
  2021. X
  2022. X##
  2023. X# The various directories that are needed in the program. Should NOT
  2024. X# have trailing '/'.
  2025. XIPDIRDEFS =    -DETCDIR=\"$(ETCDIR)\" \
  2026. X        -DDATADIR=\"$(DATADIR)\" \
  2027. X                -DNODESFILE=\"$(IPNODESFILE)\" \
  2028. X        -DPING=\"$(IPPING)\"
  2029. X
  2030. X
  2031. XOSIDIRDEFS =    -DETCDIR=\"$(ETCDIR)\" \
  2032. X        -DDATADIR=\"$(DATADIR)\" \
  2033. X                -DNODESFILE=\"$(OSINODESFILE)\" \
  2034. X        -DPING=\"$(OSIPING)\"
  2035. X
  2036. X
  2037. XCC =        cc
  2038. XIP_CDEFS =     $(SYSDEFS) $(IPDIRDEFS)  -DIP
  2039. XOSI_CDEFS =     $(SYSDEFS) $(OSIDIRDEFS) -DOSI
  2040. XLIBS =        -lnocol $(SYSLIBS)
  2041. XCFLAGS =     -g -I$(INCLUDEDIR) -L$(LIBDIR)
  2042. X
  2043. XPINGMONS =    ippingmon osipingmon
  2044. XOBJECTS =     pingmon.o poll_sites.o
  2045. X
  2046. X
  2047. X$(PINGMONS): pingmon
  2048. X
  2049. Xpingmon: reset $(OBJECTS) Makefile
  2050. X    $(CC) $(CFLAGS) $(OBJECTS) $(LIBS) -o pingmon
  2051. X    @if [ "$(PROTOCOL)" = "IP" ]; then \
  2052. X        make $(IPPING) IPPING=$(IPPING) ;\
  2053. X        cp pingmon ippingmon ;\
  2054. X        echo "Made $(PROTOCOL) version of pingmon" ;\
  2055. X        ls -lg ippingmon ;\
  2056. X     else \
  2057. X        make $(OSIPING) OSIPING=$(OSIPING)  ;\
  2058. X        cp pingmon osipingmon ;\
  2059. X        echo "Made $(PROTOCOL) version of pingmon" ;\
  2060. X        ls -lg osipingmon ;\
  2061. X     fi
  2062. X
  2063. X## The dependencies in case 'mkdep' not used
  2064. X#
  2065. X$(OBJECTS): $(INCLUDEDIR)/nocol.h  $(INCLUDEDIR)/pingmon.h 
  2066. X
  2067. X.c.o:
  2068. X    @if [ "$(PROTOCOL)" = "IP" ]; then \
  2069. X        $(CC) -c $(CFLAGS) $(IP_CDEFS)  $< ;\
  2070. X        echo "$(CC) -c $(CFLAGS) $(IP_CDEFS)  $<" ;\
  2071. X     elif [ "$(PROTOCOL)" = "OSI" ]; then \
  2072. X        $(CC) -c $(CFLAGS) $(OSI_CDEFS) $< ;\
  2073. X        echo "$(CC) -c $(CFLAGS) $(OSI_CDEFS)  $<" ;\
  2074. X     fi
  2075. X
  2076. X
  2077. X$(IPPING) $(OSIPING): IFC
  2078. X    @-[ -x "$@" ] || \
  2079. X     { \
  2080. X        echo "WARNING: $@ does not exist" ;\
  2081. X        echo "      Install $@ with proper owner and mode"; \
  2082. X        echo '      (Mode should be 4751 and owner should be root) '; \
  2083. X    exit 1 ;\
  2084. X     }
  2085. X
  2086. X# To force checking
  2087. XIFC:
  2088. X
  2089. Xinstall:     $(PINGMONS)
  2090. X    -for i in $(PINGMONS); \
  2091. X       do [ -f $$i ] && $(INSTALL) -c -m 751 $$i $(BINDIR)/ ;done
  2092. X    @echo "___Update $(IPNODESFILE), $(OSINODESFILE) with hostnames ___"
  2093. X
  2094. X## Clean up all except the newly created required binary. This cleanup allows
  2095. X# the same Makefile to make ippingmon and osipingmon
  2096. Xreset:
  2097. X    /bin/rm -f $(OBJECTS) core a.out
  2098. X
  2099. Xclean:
  2100. X    /bin/rm -f $(PINGMONS) $(OBJECTS) pingmon core a.out
  2101. X
  2102. Xrcs:
  2103. X    @echo "Doing 'rcs' in 'pingmon'"
  2104. X    @-for i in $(OBJS); do \
  2105. X        $(CO) -q `basename $$i .o`.c ;\
  2106. X      done
  2107. END_OF_FILE
  2108.   if test 3543 -ne `wc -c <'nocol-3.0/src/pingmon/Makefile'`; then
  2109.     echo shar: \"'nocol-3.0/src/pingmon/Makefile'\" unpacked with wrong size!
  2110.   fi
  2111.   # end of 'nocol-3.0/src/pingmon/Makefile'
  2112. fi
  2113. if test -f 'nocol-3.0/src/support/mping/msummary' -a "${1}" != "-c" ; then 
  2114.   echo shar: Will not clobber existing file \"'nocol-3.0/src/support/mping/msummary'\"
  2115. else
  2116.   echo shar: Extracting \"'nocol-3.0/src/support/mping/msummary'\" \(5524 characters\)
  2117.   sed "s/^X//" >'nocol-3.0/src/support/mping/msummary' <<'END_OF_FILE'
  2118. X#! /usr/local/bin/perl
  2119. X
  2120. X#
  2121. X# Run ping connectivity tests.   Ping list of addresses every 60
  2122. X# seconds and keep a reachability metric for each address.  This
  2123. X# is intended to (1) help isolate problem links, and (2) give a
  2124. X# better idea of long term trends than just the immediate results
  2125. X# of the most recent test.
  2126. X#
  2127. X
  2128. X# Command to run test
  2129. X$dataFile = "msummary.out";
  2130. X$confFile = "msummary.dat";
  2131. X$command = "mping -f $confFile |";
  2132. X$napTime = 60;        # should be 60
  2133. X$iter = 0;        # iteration count
  2134. X$cycleTime = 0;        # time for most recent poll
  2135. X
  2136. X
  2137. X#
  2138. X# These values were empiricially arrived at.  They differ markedly
  2139. X# from those used in the UNIX kernal to smooth load averages.  Those
  2140. X# values result in averages over much longer intervals than the comments
  2141. X# indicate.
  2142. X#
  2143. X# 0.00499999999999999 is the value such that when multiplied by the
  2144. X# maximum valid data value (100) produces a result less than 0.5.
  2145. X# The three values are the 5th, 15th, and 60th roots respectively.
  2146. X#
  2147. X@exp = (
  2148. X    0.3465724216,    #  5 intervals  [0.0049999999999**(1/5)]
  2149. X    0.7024218302,    # 15 intervals  [0.0049999999999**(1/15)]
  2150. X    0.9154813473,    # 60 intervals  [0.0049999999999**(1/60)]
  2151. X    
  2152. X);
  2153. X@invexp = (
  2154. X    1.0 - $exp[0],
  2155. X    1.0 - $exp[1],
  2156. X    1.0 - $exp[2],
  2157. X);
  2158. X
  2159. X#
  2160. X# Smooth a value over three intervals, depending on the value
  2161. X# of the @exp array above.  Change the averages in-place and
  2162. X# return an array of rounded values.
  2163. X#
  2164. Xsub smooth {
  2165. X    local (@tmp);
  2166. X    local ($val) = $_[3];
  2167. X    local ($i);
  2168. X
  2169. X    foreach $i (0 .. 2) {
  2170. X        $_[$i] = ($_[$i]*$exp[$i] + $invexp[$i]*$val) ;
  2171. X    }
  2172. X
  2173. X    # round to nearest whole value
  2174. X    @tmp = @_[0..2];
  2175. X    foreach (@tmp) { $_ += 0.5; }
  2176. X
  2177. X    return @tmp;
  2178. X}
  2179. X
  2180. X
  2181. X%summary = ();
  2182. X%done = ();
  2183. X
  2184. X#
  2185. X# sort things by the value associated with them in the order
  2186. X# array.  This will preserve the original order in the configuration
  2187. X# file.
  2188. X#
  2189. Xsub sortByOrder {
  2190. X    $done{$a} <=> $done{$b};
  2191. X}
  2192. X
  2193. X{
  2194. X    local ($k,$v);
  2195. X    local ($bTime, $eTime);
  2196. X    for (;;) {
  2197. X        $iter++;
  2198. X        %done = ();
  2199. X        
  2200. X        $bTime = time();
  2201. X        &getStats(*summary, *done);
  2202. X        # Delete old nodes
  2203. X        while (($k,$v) = each(%summary)) {
  2204. X            delete $summary{$k} unless defined $done{$k};
  2205. X        }
  2206. X        $eTime = time();
  2207. X        $cycleTime = $eTime - $bTime;
  2208. X        &printResults(*summary, $dataFile);
  2209. X
  2210. X        $eTime = time();
  2211. X        $cycleTime = $eTime - $bTime;
  2212. X        sleep($cycleTime >= $napTime ? $napTime : ($napTime-$cycleTime));
  2213. X    }
  2214. X}
  2215. X
  2216. Xsub getStats {
  2217. X    local (*db, *mark) = @_;
  2218. X    local (*FILE);
  2219. X    local (@j,$k,$v);
  2220. X    local ($ns,$nr,$rtt);
  2221. X    local (@avgBad,@avgRTT,@atBat,@tmp);
  2222. X
  2223. X    open(FILE, $command) || die "Can't pipe: $!";
  2224. X
  2225. X    while ($_ = <FILE>) {
  2226. X        @j = split(' ', $_);
  2227. X        $k = "$j[0]:$j[1]";
  2228. X        $ns  = $j[2];
  2229. X        $nr  = $j[3];
  2230. X        $bad = ($ns-$nr)*100/$ns;
  2231. X
  2232. X        
  2233. X        if ($v = $db{$k}) {
  2234. X            @tmp = split (':', $v);
  2235. X            @avgBad = splice(@tmp, 2, 3);
  2236. X            @avgRTT = splice(@tmp, 2, 3);
  2237. X            @atBat = splice(@tmp, 2, 2);
  2238. X        }
  2239. X        else { @avgBad = @avgRTT = (0,0,0); @atBat = (0,0); }
  2240. X
  2241. X        # if no packets were returned, putting any value in
  2242. X        # for rtt is a bit of a lie.  A zero value perturbs
  2243. X        # the long-term average.  So in this case we just
  2244. X        # copy the last average value.  In the case of a
  2245. X        # temporary disruption, the RTT average will converge
  2246. X        # toward the last valid short term average.
  2247. X        $rtt = $nr ? ($j[4] / $nr)/1000 : $avgRTT[0];
  2248. X
  2249. X        &smooth (@avgBad, $bad);
  2250. X        &smooth (@avgRTT, $rtt);
  2251. X
  2252. X        # Count how many times this system hits the reporting
  2253. X        # list
  2254. X        $atBat[0]++;
  2255. X        $atBat[1]++
  2256. X            if ($avgBad[0] >= 0.5 || $avgBad[1] >= 0.5
  2257. X                || $avgBad[2] >= 0.5);
  2258. X        $db{$k} = join(':', $bad, $rtt, @avgBad, @avgRTT, @atBat);
  2259. X
  2260. X        # store the line number of this entry in the mark
  2261. X        # array.  This is used later in the sort procedure.
  2262. X        $mark{$k} = $.;
  2263. X    }
  2264. X    close (FILE);
  2265. X}
  2266. X
  2267. Xsub printResults {
  2268. X    local (*db, $file) = @_;
  2269. X    local ($k,$v);
  2270. X    local ($sn, $sa, $ns, $nr, $rtt);
  2271. X    local (@avgBad, @avgRTT,@atBat,@tmp);
  2272. X    local ($nskipped) = 0;
  2273. X    local (*STREAM);
  2274. X    local ($bars) = "-" x 24;
  2275. X    local ($fmt) = "%-18.18s %-15.15s %3.3s %5.5s "
  2276. X        . "%3.3s %5.5s %3.3s %5.5s %3.3s %5.5s %3.3s\n",
  2277. X
  2278. X    open (STREAM, ">$file") || die "Can't open output file '$file': $!";
  2279. X    $heading = sprintf ("%-11s %-5s %5d %-6s %3d", &myctime(time()),
  2280. X        "Iter:", $iter,
  2281. X        "Cycle:", $cycleTime);
  2282. X        "current", "avg. 5", "avg. 15", "avg. 60";
  2283. X    printf STREAM
  2284. X        "%-34s %9s %9s %9s %9s\n", $heading,
  2285. X        "current", "avg. 5", "avg. 15", "avg. 60";
  2286. X    printf STREAM $fmt, "System Name", "IP Address",
  2287. X        "bad", "RTT", "bad", "RTT", "bad", "RTT", "bad", "RTT", "RPT";
  2288. X    printf STREAM $fmt, $bars, $bars, $bars, $bars, $bars, $bars, $bars,
  2289. X        $bars, $bars, $bars, $bars;
  2290. X    foreach $k (sort sortByOrder keys(%db)) {
  2291. X        $v = $db{$k};
  2292. X        ($sn, $sa) = split(":",$k);
  2293. X        ($bad,$rtt,@tmp) = split (":", $v);
  2294. X        @avgBad = splice (@tmp, 0, 3);
  2295. X        @avgRTT = splice (@tmp, 0, 3);
  2296. X        @atBat = splice (@tmp, 0, 2);
  2297. X        foreach (@avgBad) { $_ += 0.5; }
  2298. X        ($nskipped++,next) if ($avgBad[2] < 1);
  2299. X        printf STREAM
  2300. X         "%-18s %-15s %3d %5.1f %3d %5.1f %3d %5.1f %3d %5.1f %3d\n", 
  2301. X            $sn, $sa, $bad, $rtt,
  2302. X            $avgBad[0], $avgRTT[0],
  2303. X            $avgBad[1], $avgRTT[1],
  2304. X            $avgBad[2], $avgRTT[2],
  2305. X            ($atBat[1]*100/$atBat[0]);
  2306. X    }
  2307. X    print STREAM $nskipped, " entries skipped for all-0 error averages\n\n";
  2308. X    close (STREAM);
  2309. X}
  2310. X
  2311. XCONFIG: {
  2312. X    package myctime;
  2313. X
  2314. X    @DoW = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
  2315. X    @MoY = ('Jan','Feb','Mar','Apr','May','Jun',
  2316. X        'Jul','Aug','Sep','Oct','Nov','Dec');
  2317. X}
  2318. X
  2319. Xsub myctime {
  2320. X    package myctime;
  2321. X
  2322. X    local($time) = @_;
  2323. X    local($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst);
  2324. X
  2325. X    ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
  2326. X    localtime($time);
  2327. X
  2328. X    sprintf("%2d:%02d:%02d", $hour, $min, $sec);
  2329. X}
  2330. END_OF_FILE
  2331.   if test 5524 -ne `wc -c <'nocol-3.0/src/support/mping/msummary'`; then
  2332.     echo shar: \"'nocol-3.0/src/support/mping/msummary'\" unpacked with wrong size!
  2333.   fi
  2334.   chmod +x 'nocol-3.0/src/support/mping/msummary'
  2335.   # end of 'nocol-3.0/src/support/mping/msummary'
  2336. fi
  2337. if test -f 'nocol-3.0/src/support/mping/t-msummary' -a "${1}" != "-c" ; then 
  2338.   echo shar: Will not clobber existing file \"'nocol-3.0/src/support/mping/t-msummary'\"
  2339. else
  2340.   echo shar: Extracting \"'nocol-3.0/src/support/mping/t-msummary'\" \(5567 characters\)
  2341.   sed "s/^X//" >'nocol-3.0/src/support/mping/t-msummary' <<'END_OF_FILE'
  2342. X#! /usr/local/bin/perl
  2343. X
  2344. X#
  2345. X# Run ping connectivity tests.   Ping list of addresses every 60
  2346. X# seconds and keep a reachability metric for each address.  This
  2347. X# is intended to (1) help isolate problem links, and (2) give a
  2348. X# better idea of long term trends than just the immediate results
  2349. X# of the most recent test.
  2350. X#
  2351. X
  2352. X# Command to run test
  2353. X$dataFile = "msummary.out";
  2354. X$confFile = "msummary.dat";
  2355. X$command = "mping -f $confFile |";
  2356. X$napTime = 60;        # should be 60
  2357. X$iter = 0;        # iteration count
  2358. X$cycleTime = 0;        # time for most recent poll
  2359. X
  2360. X
  2361. X#
  2362. X# These values were empiricially arrived at.  They differ markedly
  2363. X# from those used in the UNIX kernal to smooth load averages.  Those
  2364. X# values result in averages over much longer intervals than the comments
  2365. X# indicate.
  2366. X#
  2367. X# 0.00499999999999999 is the value such that when multiplied by the
  2368. X# maximum valid data value (100) produces a result less than 0.5.
  2369. X# The three values are the 5th, 15th, and 60th roots respectively.
  2370. X#
  2371. X@exp = (
  2372. X    0.3465724216,    #  5 intervals  [0.0049999999999**(1/5)]
  2373. X    0.7024218302,    # 15 intervals  [0.0049999999999**(1/15)]
  2374. X    0.9154813473,    # 60 intervals  [0.0049999999999**(1/60)]
  2375. X    
  2376. X);
  2377. X@invexp = (
  2378. X    1.0 - $exp[0],
  2379. X    1.0 - $exp[1],
  2380. X    1.0 - $exp[2],
  2381. X);
  2382. X
  2383. X#
  2384. X# Smooth a value over three intervals, depending on the value
  2385. X# of the @exp array above.  Change the averages in-place and
  2386. X# return an array of rounded values.
  2387. X#
  2388. Xsub smooth {
  2389. X    local (@tmp);
  2390. X    local ($val) = $_[3];
  2391. X    local ($i);
  2392. X
  2393. X    foreach $i (0 .. 2) {
  2394. X        $_[$i] = ($_[$i]*$exp[$i] + $invexp[$i]*$val) ;
  2395. X    }
  2396. X
  2397. X    # round to nearest whole value
  2398. X    @tmp = @_[0..2];
  2399. X    foreach (@tmp) { $_ += 0.5; }
  2400. X
  2401. X    return @tmp;
  2402. X}
  2403. X
  2404. X
  2405. X%summary = ();
  2406. X%done = ();
  2407. X
  2408. X#
  2409. X# sort things by the value associated with them in the order
  2410. X# array.  This will preserve the original order in the configuration
  2411. X# file.
  2412. X#
  2413. Xsub sortByOrder {
  2414. X    $done{$a} <=> $done{$b};
  2415. X}
  2416. X
  2417. X{
  2418. X    local ($k,$v);
  2419. X    local ($bTime, $eTime);
  2420. X    for (;;) {
  2421. X        $iter++;
  2422. X        %done = ();
  2423. X        
  2424. X        $bTime = time();
  2425. X        &getStats(*summary, *done);
  2426. X        # Delete old nodes
  2427. X        while (($k,$v) = each(%summary)) {
  2428. X            delete $summary{$k} unless defined $done{$k};
  2429. X        }
  2430. X        $eTime = time();
  2431. X        $cycleTime = $eTime - $bTime;
  2432. X        &printResults(*summary, $dataFile);
  2433. X
  2434. X        $eTime = time();
  2435. X        $cycleTime = $eTime - $bTime;
  2436. X        sleep($cycleTime >= $napTime ? $napTime : ($napTime-$cycleTime));
  2437. X    }
  2438. X}
  2439. X
  2440. Xsub getStats {
  2441. X    local (*db, *mark) = @_;
  2442. X    local (*FILE);
  2443. X    local (@j,$k,$v);
  2444. X    local ($ns,$nr,$rtt);
  2445. X    local (@avgBad,@avgRTT,@atBat,@tmp);
  2446. X
  2447. X    open(FILE, $command) || die "Can't pipe: $!";
  2448. X
  2449. X    while ($_ = <FILE>) {
  2450. X        @j = split(' ', $_);
  2451. X        $k = "$j[0]:$j[1]";
  2452. X        $ns  = $j[2];
  2453. X        $nr  = $j[3];
  2454. X        $bad = ($ns-$nr)*100/$ns;
  2455. X
  2456. X        
  2457. X        if ($v = $db{$k}) {
  2458. X            @tmp = split (':', $v);
  2459. X            @avgBad = splice(@tmp, 2, 3);
  2460. X            @avgRTT = splice(@tmp, 2, 3);
  2461. X            @atBat = splice(@tmp, 2, 2);
  2462. X        }
  2463. X        else { @avgBad = @avgRTT = (0,0,0); @atBat = (0,0); }
  2464. X
  2465. X        # if no packets were returned, putting any value in
  2466. X        # for rtt is a bit of a lie.  A zero value perturbs
  2467. X        # the long-term average.  So in this case we just
  2468. X        # copy the last average value.  In the case of a
  2469. X        # temporary disruption, the RTT average will converge
  2470. X        # toward the last valid short term average.
  2471. X        $rtt = $nr ? ($j[4] / $nr)/1000 : $avgRTT[0];
  2472. X
  2473. X        &smooth (@avgBad, $bad);
  2474. X        &smooth (@avgRTT, $rtt);
  2475. X
  2476. X        # Count how many times this system hits the reporting
  2477. X        # list
  2478. X        $atBat[0]++;
  2479. X        $atBat[1]++
  2480. X            if ($avgBad[0] >= 0.5 || $avgBad[1] >= 0.5
  2481. X                || $avgBad[2] >= 0.5);
  2482. X        $db{$k} = pack ("d10", $bad, $rtt, @avgBad, @avgRTT, @atBat);
  2483. X
  2484. X        # store the line number of this entry in the mark
  2485. X        # array.  This is used later in the sort procedure.
  2486. X        $mark{$k} = $.;
  2487. X    }
  2488. X    close (FILE);
  2489. X}
  2490. X
  2491. Xsub printResults {
  2492. X    local (*db, $file) = @_;
  2493. X    local ($k,$v);
  2494. X    local ($sn, $sa, $ns, $nr, $rtt);
  2495. X    local (@avgBad, @avgRTT,@atBat,@tmp);
  2496. X    local ($nskipped) = 0;
  2497. X    local (*STREAM);
  2498. X    local ($bars) = "-" x 24;
  2499. X    local ($fmt) = "%-18.18s %-15.15s %3.3s %5.5s "
  2500. X        . "%3.3s %5.5s %3.3s %5.5s %3.3s %5.5s %3.3s\n",
  2501. X
  2502. X    open (STREAM, ">$file") || die "Can't open output file '$file': $!";
  2503. X    $heading = sprintf ("%-11s %-5s %5d %-6s %3d", &myctime(time()),
  2504. X        "Iter:", $iter,
  2505. X        "Cycle:", $cycleTime);
  2506. X        "current", "avg. 5", "avg. 15", "avg. 60";
  2507. X    printf STREAM
  2508. X        "%-34s %9s %9s %9s %9s\n", $heading,
  2509. X        "current", "avg. 5", "avg. 15", "avg. 60";
  2510. X    printf STREAM $fmt, "System Name", "IP Address",
  2511. X        "bad", "RTT", "bad", "RTT", "bad", "RTT", "bad", "RTT", "RPT";
  2512. X    printf STREAM $fmt, $bars, $bars, $bars, $bars, $bars, $bars, $bars,
  2513. X        $bars, $bars, $bars, $bars;
  2514. X    foreach $k (sort sortByOrder keys(%db)) {
  2515. X        $v = $db{$k};
  2516. X        ($sn, $sa) = split(":",$k);
  2517. X        ($bad,$rtt,@tmp) = unpack ("d10", $v);
  2518. X        @avgBad = splice (@tmp, 0, 3);
  2519. X        @avgRTT = splice (@tmp, 0, 3);
  2520. X        @atBat = splice (@tmp, 0, 2);
  2521. X        foreach (@avgBad) { $_ += 0.5; }
  2522. X        ($nskipped++,next)
  2523. X            if $avgBad[0] < 1 && $avgBad[1] < 1 && $avgBad[2] < 1;
  2524. X        printf STREAM
  2525. X         "%-18s %-15s %3d %5.1f %3d %5.1f %3d %5.1f %3d %5.1f %3d\n", 
  2526. X            $sn, $sa, $bad, $rtt,
  2527. X            $avgBad[0], $avgRTT[0],
  2528. X            $avgBad[1], $avgRTT[1],
  2529. X            $avgBad[2], $avgRTT[2],
  2530. X            ($atBat[1]*100/$atBat[0]);
  2531. X    }
  2532. X    print STREAM $nskipped, " entries skipped for all-0 error averages\n\n";
  2533. X    close (STREAM);
  2534. X}
  2535. X
  2536. XCONFIG: {
  2537. X    package myctime;
  2538. X
  2539. X    @DoW = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
  2540. X    @MoY = ('Jan','Feb','Mar','Apr','May','Jun',
  2541. X        'Jul','Aug','Sep','Oct','Nov','Dec');
  2542. X}
  2543. X
  2544. Xsub myctime {
  2545. X    package myctime;
  2546. X
  2547. X    local($time) = @_;
  2548. X    local($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst);
  2549. X
  2550. X    ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
  2551. X    localtime($time);
  2552. X
  2553. X    sprintf("%2d:%02d:%02d", $hour, $min, $sec);
  2554. X}
  2555. END_OF_FILE
  2556.   if test 5567 -ne `wc -c <'nocol-3.0/src/support/mping/t-msummary'`; then
  2557.     echo shar: \"'nocol-3.0/src/support/mping/t-msummary'\" unpacked with wrong size!
  2558.   fi
  2559.   chmod +x 'nocol-3.0/src/support/mping/t-msummary'
  2560.   # end of 'nocol-3.0/src/support/mping/t-msummary'
  2561. fi
  2562. echo shar: End of archive 22 \(of 26\).
  2563. cp /dev/null ark22isdone
  2564. MISSING=""
  2565. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ; do
  2566.     if test ! -f ark${I}isdone ; then
  2567.     MISSING="${MISSING} ${I}"
  2568.     fi
  2569. done
  2570. if test "${MISSING}" = "" ; then
  2571.     echo You have unpacked all 26 archives.
  2572.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2573. else
  2574.     echo You still must unpack the following archives:
  2575.     echo "        " ${MISSING}
  2576. fi
  2577. exit 0
  2578. exit 0 # Just in case...
  2579.