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

  1. Newsgroups: comp.sources.misc
  2. From: vikas@jvnc.net (Vikas Aggarwal)
  3. Subject: v40i150:  nocol - Network Monitoring System, Part20/26
  4. Message-ID: <1993Nov24.163701.1676@sparky.sterling.com>
  5. X-Md4-Signature: 15b38fa5e8e1032de1aac7c256bd0884
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Wed, 24 Nov 1993 16:37:01 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: vikas@jvnc.net (Vikas Aggarwal)
  12. Posting-number: Volume 40, Issue 150
  13. Archive-name: nocol/part20
  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/Makefile nocol-3.0/src/doc/nocol-prog.3
  21. #   nocol-3.0/src/include/netmon.h
  22. #   nocol-3.0/src/netmon/build_display.c nocol-3.0/src/netmon/netmon.c
  23. #   nocol-3.0/src/perlnocol/snmp-modemmon
  24. #   nocol-3.0/src/pingmon/poll_sites.c
  25. #   nocol-3.0/src/support/mping/spqr.doc nocol-3.0/src/tpmon/tpmon.c
  26. #   nocol-3.0/src/trapmon/Makefile
  27. # Wrapped by kent@sparky on Tue Nov  9 22:22:24 1993
  28. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  29. echo If this archive is complete, you will see the following message:
  30. echo '          "shar: End of archive 20 (of 26)."'
  31. if test -f 'nocol-3.0/src/Makefile' -a "${1}" != "-c" ; then 
  32.   echo shar: Will not clobber existing file \"'nocol-3.0/src/Makefile'\"
  33. else
  34.   echo shar: Extracting \"'nocol-3.0/src/Makefile'\" \(7633 characters\)
  35.   sed "s/^X//" >'nocol-3.0/src/Makefile' <<'END_OF_FILE'
  36. X# $Header: /home/aggarwal/lsrc/nocol/src/RCS/Makefile,v 1.7 1993/10/30 03:07:14 aggarwal Exp $
  37. X#
  38. X# Makefile for 'nocol'. This file simply calls on other Makefiles in
  39. X# the subdirectories to do all the work. All the definitions are used
  40. X# by the other Makefiles which then do all the compile time definitions.
  41. X#
  42. X# Check: SRCDIR, TOP, PING, NLOG_HOST, SYSLIBS, NEEDOBJS
  43. X#
  44. X# To 'make' for only one program, use 
  45. X#    make "SRCS=trapmon" [install|clean]
  46. X#
  47. X
  48. X##
  49. X# CHECK THE VALUE OF IPPING and OSIPING below.
  50. X
  51. X##
  52. X# Set TOP here to a directory where everything will be installed (etc, data)
  53. X# 'nocol' does a chroot to this directory when it runs.
  54. XTOP  =        /nocol
  55. X
  56. X##
  57. X# Set SRCDIR to the toplevel location of the NOCOL sources (this directory ?)
  58. XSRCDIR=        $(TOP)/src
  59. X
  60. X##
  61. X# Set MANDIR for the manpages and MANEXT for the man pages extension
  62. XMANDIR = $(TOP)/man
  63. XMANEXT = n
  64. X
  65. X##
  66. X# Library calls not a part of your system. Define NEEDOBJS here.
  67. X# These will be compiled into 'lib/libnocol'
  68. X#   putenv.o        for putenv() library call - on NeXT
  69. X#   random.o        if you don't have random()  - on Solaris, HP
  70. X#   bstring.o        for bcmp() bzero()  bcopy() - on Solaris, HP
  71. X#   ftime.o        for ftime() - on Solaris, HP
  72. X#   
  73. XNEEDOBJS =    # putenv.o random.o
  74. X
  75. X##
  76. X# If you also want to make the OSI version of 'pingmon', then set MAKEOSI
  77. X# to 'YES', else set to NO
  78. XMAKEOSI = "NO"
  79. X
  80. X##
  81. X# Hostname of the machine that will be running the noclogd logging
  82. X# daemon (can give IP address instead).
  83. X#
  84. XNLOG_HOST =    nocol.jvnc.net
  85. X
  86. X##
  87. X# The special system definitions. Define:
  88. X#  -DMULTIPING        If setting IPPING to use 'multiping'. Check IPPING also
  89. X#
  90. XSYSDEFS =    -DMULTIPING
  91. X
  92. X##
  93. X# Special libraries that might be needed to link on your system.
  94. X#  -lresolv        On SunOS
  95. X#  -lsocket        On Solaris
  96. X#  -lnsl        On Solaris
  97. X#
  98. XSYSLIBS =    -lresolv # -lsocket -lnsl
  99. X
  100. X##
  101. X# special defines for  pingmon. Can have an IP ping and/or OSI ping.
  102. X#    Set IPPING to /etc/ping or $(BINDIR)/ping or $(BINDIR)/multiping
  103. X#    Make sure that the output of the ping command is something like:
  104. X#        % ping -s nisc.jvnc.net 100 5
  105. X#    See INSTALL or pingmon/poll_sites.c for more details.
  106. X#
  107. X#    If using 'multiping', also set SYSDEFS value.
  108. X#
  109. XIPPING =        $(BINDIR)/multiping
  110. XOSIPING =       /usr/sunlink/osi/etc/osi_ping
  111. X
  112. X## Location of useful utility programs
  113. X#   CO        location of the 'RCS' check-out program (unless in path)
  114. X#   RANLIB    if you don't have it, set to 'touch' or 'ls'. Solaris/HP
  115. X#        systems dont have it.
  116. X#   INSTALL    for old versions use 'install'. For new OS's use 
  117. X#        $(SRCDIR)/utility/myinstall (HP/Solaris systems)
  118. X#   
  119. XCO =        co
  120. XRANLIB =    ranlib
  121. XINSTALL =    install
  122. X
  123. X
  124. X# Which programs are to be compiled and installed.
  125. X#    eventselect    print out events that match certain criterion
  126. X#    genmon        Generic monitoring interface (ascii to nocol struct)
  127. X#    netmon        the nocol display (installed as nocol)
  128. X#    noclog        the noclogd logging daemon
  129. X#    nsmon        Nameserver monitor
  130. X#    pingmon        Reachability monitor via 'ping'
  131. X#    portmon        Check TCP ports on various machines.
  132. X#    tpmon        Data thruput monitor
  133. X#    trapmon        SNMP trap monitor
  134. X#    utility        Small utility programs
  135. X#    doc        Documentation and manual pages
  136. X#
  137. XSRCS =       lib eventselect genmon netmon noclog nsmon perlnocol \
  138. X        pingmon portmon tpmon trapmon \
  139. X        utility doc
  140. X
  141. X####
  142. X####    Can leave the rest alone
  143. X####
  144. X
  145. X# These are defined here so that install can create these directories
  146. X# if they do not exist.
  147. X#    BINDIR        where the programs are installed
  148. X#    ETCDIR        location of configuration files
  149. X#    DATADIR        where datafiles for monitoring programs are created
  150. X#    MSGSDIR        for message files that the nocol display shows in
  151. X#            in the 'messages' sub-window
  152. XBINDIR=     $(TOP)/bin
  153. XETCDIR=        $(TOP)/etc
  154. XDATADIR=    $(TOP)/data
  155. XMSGSDIR=    $(TOP)/msgs
  156. X
  157. X# This is needed for building and linking common routines.
  158. XLIBDIR=        $(SRCDIR)/lib
  159. X
  160. X# Directory/file definitions that override the ones in the other 'Makefile's
  161. XDIRDEFS=    TOP="$(TOP)" \
  162. X        SRCDIR="$(SRCDIR)" \
  163. X        LIBDIR="$(LIBDIR)" \
  164. X        BINDIR="$(BINDIR)" \
  165. X        ETCDIR="$(ETCDIR)" \
  166. X        DATADIR="$(DATADIR)" \
  167. X        MSGSDIR="$(MSGSDIR)" \
  168. X        MANDIR="$(MANDIR)" \
  169. X        IPPING="$(IPPING)" \
  170. X        OSIPING="$(OSIPING)"
  171. X
  172. X# General definitions that override the ones in the other 'Makefile's
  173. XMAKEDEFS=    NLOG_HOST="$(NLOG_HOST)" \
  174. X        MANEXT="$(MANEXT)" NEEDOBJS="$(NEEDOBJS)" \
  175. X        SYSDEFS="$(SYSDEFS)" SYSLIBS="$(SYSLIBS)" \
  176. X        CO="$(CO)" RANLIB="$(RANLIB)" INSTALL="$(INSTALL)"
  177. X
  178. X##
  179. X# Compile defs
  180. X#    CC    which C compiler. 'GCC' earlier than 2.x might fail on Sparc
  181. X#    CFLAGS    -I<location of includes> -DDEBUG
  182. XCC =        cc
  183. XCFLAGS=        -g  -I$(SRCDIR)/include -L$(LIBDIR)
  184. X
  185. X##
  186. X# This is the list of files that need to be 'tar-red'. Using the FF option
  187. X# in the tar command and also excluding the RCS directories further down.
  188. XDIST =    COPYRIGHT HISTORY INSTALL PORTING README Makefile version.h \
  189. X    contrib cmu-snmp doc include lib perlnocol support utility \
  190. X    eventselect genmon netmon noclog nsmon pingmon portmon tpmon trapmon
  191. X
  192. X
  193. Xall:    libnocol.a
  194. X    @-for i in $(SRCS); do \
  195. X      ( echo "" ; echo "MAKING IN $$i" ; echo "----------" ; cd $$i ; \
  196. X        make $(MFLAGS) CC="$(CC)" CFLAGS="$(CFLAGS)" $(MAKEDEFS) $(DIRDEFS) ; \
  197. X        if [ $$i = "pingmon" ]; then\
  198. X          if [ "$(MAKEOSI)" = "YES" ]; then \
  199. X            make $(MFLAGS) osipingmon PROTOCOL=OSI CC="$(CC)" \
  200. X              CFLAGS="$(CFLAGS)" $(MAKEDEFS) $(DIRDEFS) ;\
  201. X          else \
  202. X            : ;\
  203. X          fi ;\
  204. X        else \
  205. X          : ;\
  206. X        fi ;\
  207. X         ) \
  208. X     done
  209. X
  210. Xlib:    libnocol.a
  211. Xlibnocol.a:
  212. X      @echo "" ; echo "MAKING IN lib" ; echo "----------"
  213. X      @( cd lib ; \
  214. X        make $(MFLAGS) CC="$(CC)" CFLAGS="$(CFLAGS)" $(MAKEDEFS) $(DIRDEFS) ;) 
  215. X
  216. X
  217. X## Ultrix make balked at the tests for directories, hence the second test
  218. Xinstall:    lib
  219. X    -[ -d $(TOP) ] || mkdir  $(TOP)
  220. X    -[ -d $(DATADIR) ] || mkdir $(DATADIR)
  221. X    -[ -d $(ETCDIR) ] || mkdir $(ETCDIR)
  222. X    -[ -d $(ETCDIR)/samples ] || mkdir $(ETCDIR)/samples
  223. X    -[ -d $(BINDIR) ] || mkdir $(BINDIR)
  224. X    [ -d $(TOP) ] && [ -d $(DATADIR) ] && [ -d $(ETCDIR) ] \
  225. X        && [ -d $(BINDIR) ]
  226. X    @-(touch NoColL ; $(INSTALL) -c -m 750 NoColL /tmp/;) >/dev/null 2>&1 ;
  227. X    @(if [ -f /tmp/NoColL ]; then rm -f NoColL /tmp/NoColL; else \
  228. X      echo "YOU HAVE AN INCOMPATIBLE install, use 'myinstall' instead" ;\
  229. X      rm -f NoColL /tmp/NoColL ; exit 1 ; fi)
  230. X
  231. X    @echo make $(MFLAGS) CC="$(CC)" CFLAGS="$(CFLAGS)" \
  232. X        $(MAKEDEFS) $(DIRDEFS) install ;
  233. X    @-for i in $(SRCS); do \
  234. X      ( echo "" ; echo "MAKING IN $$i" ; echo "----------" ; cd $$i ; \
  235. X        make $(MFLAGS) CC="$(CC)" CFLAGS="$(CFLAGS)" \
  236. X            $(MAKEDEFS) $(DIRDEFS) install ; ) ;\
  237. X    done
  238. X    @-cp pingmon/ipnodes */*-confg $(ETCDIR)/samples/
  239. X
  240. Xtar:    nocol.tar
  241. X
  242. Xnocol.tar:
  243. X    @( if [ ! -d /var/tmp/t ]; then mkdir /var/tmp/t ;fi ;\
  244. X       if [ ! -d /var/tmp/t/nocol ]; then mkdir /var/tmp/t/nocol ; fi ;\
  245. X       if [ ! -d /var/tmp/t/nocol ]; then \
  246. X        echo "Fatal error: cannot create directory  /var/tmp/t/nocol";\
  247. X        exit 1 ; fi ;\
  248. X       (cd /var/tmp/t/nocol/ ; rm -rf XCLUDEFILES src ; mkdir src) ;\
  249. X       for i in $(DIST) ; do \
  250. X        find $$i \( -name RCS -o -name '*~' \) -print  >> /var/tmp/t/nocol/XCLUDEFILES ;\
  251. X       done ;\
  252. X       echo "Copying src files to tmp location" ;\
  253. X       tar cfX - /var/tmp/t/nocol/XCLUDEFILES $(DIST) |\
  254. X             ( cd /var/tmp/t/nocol/src ; tar xf -) ;\
  255. X       rm -f /var/tmp/t/nocol/XCLUDEFILES ;\
  256. X       cd /var/tmp/t/ ;\
  257. X       echo "*** Present working directory is `pwd` ***" ;\
  258. X       if [ ! `pwd` = '/var/tmp/t' ]; then \
  259. X        echo "FATAL ERROR, couldn't cd to tmp dir" ;\
  260. X        exit 1 ;\
  261. X       fi ;\
  262. X       tar cf nocol.tar nocol )
  263. X    @( mv /var/tmp/t/nocol.tar nocol.tar ;\
  264. X        /bin/rm -rf /var/tmp/t ;\
  265. X        tar tf nocol.tar )
  266. X    @echo "CREATED nocol.tar"
  267. X        
  268. X
  269. Xclean:
  270. X    @for i in $(SRCS); do \
  271. X        ( cd $$i ; make $(MFLAGS) $(DIRDEFS) $(MAKEDEFS) clean ; ) ;\
  272. X    done
  273. X
  274. Xrcs:
  275. X    @-for i in $(SRCS); do \
  276. X        ( cd $$i ; make $(MFLAGS) $(MAKEDEFS) rcs ; ) ;\
  277. X    done 
  278. X###
  279. END_OF_FILE
  280.   if test 7633 -ne `wc -c <'nocol-3.0/src/Makefile'`; then
  281.     echo shar: \"'nocol-3.0/src/Makefile'\" unpacked with wrong size!
  282.   fi
  283.   # end of 'nocol-3.0/src/Makefile'
  284. fi
  285. if test -f 'nocol-3.0/src/doc/nocol-prog.3' -a "${1}" != "-c" ; then 
  286.   echo shar: Will not clobber existing file \"'nocol-3.0/src/doc/nocol-prog.3'\"
  287. else
  288.   echo shar: Extracting \"'nocol-3.0/src/doc/nocol-prog.3'\" \(7994 characters\)
  289.   sed "s/^X//" >'nocol-3.0/src/doc/nocol-prog.3' <<'END_OF_FILE'
  290. X.\" $Header: /home/aggarwal/lsrc/nocol/src/doc/RCS/nocol-prog.3,v 1.4 1993/10/28 16:38:03 aggarwal Exp $
  291. X.\"
  292. X.TH NOCOL-PROG 3 "October 1, 1993"
  293. X.SH NAME
  294. Xnocol \- NOCOL design and data structures
  295. X.SH SYNOPSIS
  296. XThis section describes the design and data structures in NOCOL. This section
  297. Xis intended  to be a programmers aid to understanding the overall design of
  298. XNOCOL.
  299. X.SH DESCRIPTION
  300. X.LP
  301. XThe original initiative for developing NOCOL was:
  302. X.in +.25i
  303. X.IP 1.
  304. XWhile monitoring a system, the severity of various events is pre-determined
  305. Xand the user can select the severity level at which he/she should be 
  306. Xnotified.
  307. X.IP 2.
  308. XDisplay events only at the desired level of severity and nothing else.
  309. X.IP 3. 
  310. XHave only \fIone\fR set of monitoring agents but multiple display
  311. Xagents all processing the same data.
  312. X.IP 4.
  313. XThe display module can also be run on a simple TTY interface so that the
  314. Xsystem can be monitored using a simple VT type terminal.
  315. X.IP 5.
  316. XTo have the ability to add on monitoring agents as and when necessary with
  317. Xminimum changes to existing monitors.
  318. X.IP 6.
  319. XTo be able to add on additional (possibly intelligent) post-processors for the
  320. Xdata.
  321. X.IP 7.
  322. XTo have the capability to monitor \fIany\fR entity (network routers, system
  323. Xload, modem line usage, system processes, etc.) in any protocol (IP, OSI,
  324. XDECnet) desired.
  325. X
  326. X.SH EVENT STRUCTURE
  327. X.LP
  328. XThe \fIEVENT\fR data structure is defined in \fInocol.h\fR. All nocol data
  329. Xmust be a sequence of this structure. Other than that, the various modules
  330. Xcan be as independent as possible.
  331. X
  332. XThe various fields in the structure are:
  333. X.RS
  334. X.ta \w'#define'u +\w'fsid_t\0\0'u +\w'f_spare[7]\0\0'u
  335. X.sp .5
  336. X.nf
  337. X.ft B
  338. Xtypedef struct
  339. X{
  340. X    char             sender;        /* sender/program name */
  341. X    SITE             site;          /* site name, address */
  342. X    VAR              var;           /* variable name, value, threshold, units */
  343. X    unsigned char    mon;           /* 1 to 12 for month */
  344. X    unsigned char    day;           /* 1 to 31 for day */
  345. X    unsigned char    hour;          /* 0 to 23 for hour */
  346. X    unsigned char    min;           /* 0 to 59 for minute */
  347. X    unsigned char    severity;      /* event severity 1->4 */
  348. X    unsigned char    logseverity;   /* severity at which event is logged */
  349. X    unsigned char    nocop;         /* ops flag indicating STATE */
  350. X} EVENT;
  351. X.ft R
  352. X.fi
  353. X.RE
  354. X.LP
  355. XThe \fIsender\fR  field is typically used to identify the monitoring program.
  356. XThe site \fIname\fR is generally a hostname or a shorter identifiable
  357. Xname of the entitity being monitored. The site \fIaddress\fR 
  358. Xfield is large and the intent is that it can accommodate IP, OSI or any other
  359. Xaddress/identification needed by the monitoring programs so that once they
  360. Xstart up, they can work directly from the output data files by using the
  361. XEVENT structure and not having to parse configuration files, etc. every time.
  362. XIn some monitors, it can also be the filename, or route being monitored.
  363. X
  364. XThe \fIvariable\fR  name field is self-explanatory\- it can be 
  365. Xreachability, trap-type, thruput, bgp-route, load, diskio, etc.
  366. XThe value, threshold and units are further used to give more information
  367. Xabout the variable.
  368. X
  369. XThe date and time fields record the time that the site was
  370. X.I first
  371. Xdetected in the current state.
  372. X
  373. XThe \fIseverity\fR of the event varies from 1 (=CRITICAL) to 4 (=INFO). 
  374. XThe monitors generally escalate the severity in each pass, so that
  375. Xthere is a gradual and repeated test before an event is marked as
  376. XCRITICAL, etc. Furthermore, each monitor has its own MAX_SEVERITY
  377. X.RI ( e.g.
  378. Xfor the reachability monitor
  379. X.IR pingmon ,
  380. Xthe maximum possible severity level is CRITICAL while for the
  381. X.I tpmon
  382. Xthruput monitor, the maximum possible severity level is WARNING).
  383. XA nocol library call
  384. X.I update_event
  385. Xhas been provided to escalate/reset the severity and to log the
  386. Xevent if there is a change in the severity level.
  387. X
  388. XThe \fIloglevel\fR field is used to indicate the severity level at
  389. Xwhich the event should be logged. This field is used by the logging
  390. Xdaemon in determining how/where to log the event.
  391. X
  392. XThe \fInocop\fR is for setting various boolean options associated with each
  393. Xevent (like status UP, DOWN, UNKNOWN, TEST, NODISPLAY)- note that UP, DOWN,
  394. XUNKNOWN are all mutually exclusive, the \fISETF_UPDOUN\fR macro accomplishes
  395. Xthe mutual exclusion.
  396. XThe TEST flag is useful for the post-processors which perform an operation on
  397. Xa site reaching a certain level of severity, and the NODISPLAY option is
  398. Xuseful if a particular site is not to be displayed in the 
  399. X.BR nocol (1)
  400. Xdisplay but other post-processors need to process the data.
  401. XMost of the monitors parse the config file and create an output data file
  402. Xwith the static structure values in it and the \fInocop\fR UNKNOWN flag set.
  403. XThey then read a single event from the datafile and poll the site. New values
  404. Xare inserted and the structure written back to disk.
  405. X
  406. X.SH LIBNOCOL.A
  407. X.LP
  408. XA collection of useful routines have been merged into a NOCOL library\-
  409. X.I libnocol.a
  410. Xwith which all the various monitors are linked during compile time.
  411. XFunctions to create a new 'pid' file and log the PID and hostname, 
  412. Xto update an event's  values based on the new status, etc. are available.
  413. XOf these, 
  414. X.I update_event
  415. Xis important\-  this function takes a pointer to an event, status
  416. X(UP or DOWN) and maximumseverity. It then updates the event's severity,
  417. Xloglevel and also logs the event to 
  418. X.I noclogd
  419. Xif appropriate.
  420. X
  421. X.SH LOGGING
  422. XThe various NOCOL monitors log events to a daemon-
  423. X.B noclogd
  424. X.I (8)
  425. Xat port NLOG_PORT (see the
  426. X.I noclogd.h
  427. Xinclude file for the port number). The function
  428. X.I eventlog()
  429. Xis available in the 
  430. X.I libnocol.a 
  431. Xlibrary and can be called with the
  432. Xevent structure as a parameter. The monitor is responsible for filling
  433. Xin the
  434. X.I loglevel
  435. Xfield in the EVENT structure, and the function
  436. X.I eventlog()
  437. Xwill log the event to the noclogd daemon.
  438. XAs a design note, keep in mind that it is worthwhile logging ONLY when the
  439. Xseverity
  440. X.B changes
  441. Xinstead of logging every pass made.
  442. XAlso, if a site is in CRITICAL
  443. Xlevel (as an example), then it is typically logged at loglevel=CRITICAL
  444. Xwhen the site first goes into CRITICAL state. Importantly, when the site
  445. Xgoes 
  446. X.I back
  447. Xto INFO level, the monitor should log this event at the earlier CRITICAL 
  448. Xstatus so that the person/programs
  449. Xparsing the CRITICAL logs can see when the site came out of critical status.
  450. XThe
  451. X.I update_event()
  452. Xlibrary call in NOCOL does this bit of 'complicated' manipulation of the
  453. Xloglevel (sets loglevel to the old severity if the status changes to UP).
  454. X
  455. X.SH GENMON
  456. XThe
  457. X.I genmon
  458. Xprogram provides a generic monitoring interface for writing new monitors.
  459. XIt converts text lines in the logfile format into nocol EVENT structures
  460. Xand writes them out. Thus, a simple shell script that monitors anything
  461. Xcan call
  462. X.I genmon
  463. Xwith a text line and the program will convert the line into a NOCOL
  464. Xevent strutcure. See the 
  465. X.IR genmon (8)
  466. Xmanual page for more information on this program.
  467. X
  468. X.SH DEVELOPING NEW MONITORS
  469. XTo do additional development on a monitor, the 
  470. X.I pingmon, nsmon, tpmon
  471. Xare very similar and based on the same logic so they should provide good
  472. Xexamples of how to do things.
  473. XTypical procedure flow is:
  474. X.RS
  475. X.sp .5
  476. X.nf
  477. X  Read configuration file
  478. X  Init nocol EVENT data structures
  479. X  Do test
  480. X  Update EVENT data structure
  481. X  Write out to datafile (as a group or individually)
  482. X  Sleep before next round of tests
  483. X.fi
  484. X.RE
  485. X
  486. XThe
  487. X.BR genmon (8)
  488. Xprogram provides a simple and easy interface to developing new monitors
  489. Xfor monitoring practically
  490. X.IR anything .
  491. XA collection of useful PERL routines and library is also provided.
  492. X
  493. X.\" --------------------------------------------
  494. X.SH AUTHOR
  495. X.nf
  496. XVikas Aggarwal, vikas@jvnc.net
  497. X.fi
  498. XAdditions by a lot of other folks... the PERL routines were provided by
  499. XJohn M. Wobus (jmwobus@mailbox.syr.edu).
  500. X.SH SEE ALSO
  501. Xnocol(1) nocol-prog(3) perlnocol(3)
  502. Xeventselect(8) genmon(8) noclogd(8) nocol-overview(8)
  503. Xnocol-utility(8) nsmon(8) pingmon(8) portmon(8) 
  504. Xtpmon(8) trapmon(8)
  505. X
  506. END_OF_FILE
  507.   if test 7994 -ne `wc -c <'nocol-3.0/src/doc/nocol-prog.3'`; then
  508.     echo shar: \"'nocol-3.0/src/doc/nocol-prog.3'\" unpacked with wrong size!
  509.   fi
  510.   # end of 'nocol-3.0/src/doc/nocol-prog.3'
  511. fi
  512. if test -f 'nocol-3.0/src/include/netmon.h' -a "${1}" != "-c" ; then 
  513.   echo shar: Will not clobber existing file \"'nocol-3.0/src/include/netmon.h'\"
  514. else
  515.   echo shar: Extracting \"'nocol-3.0/src/include/netmon.h'\" \(7298 characters\)
  516.   sed "s/^X//" >'nocol-3.0/src/include/netmon.h' <<'END_OF_FILE'
  517. X/*
  518. X** $Header: /home/aggarwal/lsrc/nocol/src/include/RCS/netmon.h,v 1.15 1993/10/30 02:35:56 aggarwal Exp $
  519. X*/
  520. X
  521. X/*
  522. X**        INCLUDE FILES
  523. X*/
  524. X#include "nocol.h"
  525. X#include <ctype.h>
  526. X#include <signal.h>
  527. X
  528. X#include <curses.h>        /* since WINDOW definitions are here    */
  529. X
  530. X/* #include <sys/dir.h>        /* Older systems, used 'direct' not 'dirent' */
  531. X#include <dirent.h>
  532. X
  533. X/*
  534. X * For 4.2 curses.
  535. X */
  536. X#if defined(VMS) || defined(__convex__) || defined(sequent)
  537. X# ifndef cbreak
  538. X#  define cbreak crmode
  539. X# endif
  540. X# ifndef nocbreak
  541. X#  define nocbreak nocrmode
  542. X# endif
  543. X#endif
  544. X
  545. X/*
  546. X * Usually defined in ttychars.h.
  547. X */
  548. X#ifndef ESC             /* ESCAPE character */
  549. X#define ESC 033
  550. X#endif
  551. X
  552. X#ifndef RUBOUT
  553. X#define RUBOUT            '\177'
  554. X#endif
  555. X
  556. X#ifndef erasechar()
  557. X#define erasechar()    RUBOUT
  558. X#endif
  559. X
  560. X#ifdef CTRL             /* Some implementations do a: c & 037 (assume int) */
  561. X#undef CTRL             /* and some do 'c' & 037, so use our version... */
  562. X#endif  /* CTRL */
  563. X#define CTRL(c)         (c & 037)    /* treat as an integer */
  564. X
  565. X#ifndef beep                /* crude way of doing it.. */
  566. X#define beep() (fprintf (stderr, "%c", 007))
  567. X#endif    /* beep */
  568. X
  569. X#ifndef max
  570. X#define max(a, b)    ((a) > (b) ? (a) : (b))
  571. X#endif    /* endif max */
  572. X
  573. X/*
  574. X *        FILE DEFINITIONS
  575. X *
  576. X * All files in the DATADIR are opened and processed and their output is
  577. X * displayed. The files have records in the format described in 'nocol.h'
  578. X *
  579. X * The 'msgsdir' is used for the message display. Any file in this directory
  580. X * will be treated as a ascii text file and its contents will be displayed in
  581. X * the 'Message' sub-window.
  582. X */
  583. X#ifndef DATADIR                    /* for default location    */
  584. X#define DATADIR     "../../data"            /* dont miss quotes    */
  585. X#endif
  586. X#ifndef MSGSDIR                    /* for default location    */
  587. X#define MSGSDIR     "../../msgs"            /* dont miss quotes    */
  588. X#endif
  589. X#ifndef HELPFILE
  590. X#define HELPFILE     "./netmon-help"
  591. X#endif
  592. X
  593. X/*
  594. X * Define NETLOG if you want to invoke 'netlog' from netmon when the user
  595. X * hits the 'n' option. This is invoking another program so be careful in who
  596. X * is allowed access to this program.
  597. X */
  598. X/* #define NETLOG    /* */
  599. X
  600. X/*
  601. X * 'netmon' extracts the terminal capabilities from /etc/termcap. Some
  602. X * terminals are very common and are present in every 'termcap', so you
  603. X * can list those terminals here to prevent doing a lookup using 'tgetent'.
  604. X *
  605. X * On the other hand, there are some terminals in /etc/termcap that are
  606. X * set by standard programs by default (like 'network' or 'ethernet', in
  607. X * which case you might want to query the user for the terminal type
  608. X * instead of accepting them as 'dumb' right away. List those terminals
  609. X * here too.
  610. X *
  611. X */
  612. X
  613. X#define GOODTERMINALS    "vt100", "vt200", "xterm", "sun"
  614. X#define BADTERMINALS    "ethernet", "network", "dialup"
  615. X
  616. X
  617. X/*******************  Rest is fairly standard ****************************/
  618. X
  619. X/*
  620. X**        CONSTANTS
  621. X*/
  622. X#define MAXLINE     127                   /* LINE lengths        */
  623. X#define MAXWORD        15
  624. X#define PAUSE        15            /* wait secs for poll()    */
  625. X
  626. X/*+ 
  627. X** The various display flags
  628. X**/
  629. X
  630. X#define emode 0x1        /* expanded display (132 cols) */
  631. X#define debug 0x2        /* netmon debug mode */
  632. X#define quiet 0x4        /* toggle bell off or on */
  633. X
  634. X/*
  635. X**    Global definitions
  636. X*/
  637. X
  638. Xchar *prognm;                    /* program name        */
  639. Xchar *datadir ;                    /* Dir of data files    */
  640. Xchar *msgsdir ;                    /* Dir with text msg files */
  641. Xchar *helpfile ;                /* help file         */
  642. Xchar bolds[MAXWORD];                /* Bold sequence    */
  643. Xchar bolde[MAXWORD];                /* Bold end sequence    */
  644. Xchar clscr[MAXWORD];                    /* Clear screen sequence */
  645. Xchar bellstr[MAXWORD];                /* Bell sequence */
  646. Xint  level,                    /* display level    */
  647. X  options,                    /* user options        */
  648. X  page,                        /* Page number        */
  649. X  msg_on ;                    /* toggle for msg_dpy()    */
  650. Xint  entered_curses ;                /* so done can call endwin */
  651. Xint titlesz, hdrsz, promptsz,             /* various window sizes    */
  652. X  msgtitlesz, msgsz, eventsz ;
  653. Xbool  frozen ;                    /* indefinite poll wait    */
  654. X
  655. Xextern char *good_terminals[],
  656. X  *bad_terminals[] ;                /* defined in main()    */
  657. Xextern char *tgetstr() ;            /* 'termcap' routine    */
  658. Xint outchar() ;                    /* func for tgetstr() */
  659. X
  660. X/*
  661. X * The netmon screen is made up of several subwindows. This struct is
  662. X * essentially a list of all the windows on the main netmon screen.
  663. X */
  664. Xstruct allwins
  665. X{
  666. X    WINDOW        *wmain;
  667. X    WINDOW         *wtitle;            /* the title window    */
  668. X    WINDOW    *whdr;                /* the column headers    */
  669. X    WINDOW    *wevent;            /* the event window    */
  670. X    WINDOW    *wmsgtitle;            /* message window title    */
  671. X    WINDOW    *wmsg;                /* the small msg win    */
  672. X    WINDOW    *wprompt;            /* the prompt window    */
  673. X} aw;                /* aw allocates storage for the struct    */
  674. X
  675. X/*  Window sizes:
  676. X** Initially 'wevent' size is computed as the remaining lines after all 
  677. X** else. After that it can be changed by the user.
  678. X*/
  679. X
  680. X#define TITLESZ        2            /* one blank line    */
  681. X#define HDRSZ        2            /* one blank line    */
  682. X#define MSGTITLESZ    2            /* one blank line    */
  683. X#define MSGSZ        3            /* Messages window    */
  684. X#define PROMPTSZ    2            /* one blank line above    */
  685. X#define EVENTSZ        LINES - (TITLESZ+HDRSZ+MSGTITLESZ+MSGSZ+PROMPTSZ)
  686. X
  687. X#define MNCOLS        80        /* depends on extended display    */
  688. X
  689. X/*+ 
  690. X** Display strings and formats
  691. X*/
  692. X
  693. X#define PROMPTA "Enter option, 'q' to quit, 'h' for help: "
  694. X#define PROMPTB "Enter option, or any other key for next screen: "
  695. X
  696. X/*
  697. X * The header names and the formats are coded here. They depend on the 'event'
  698. X * structure and should be modified with care. Make sure that you match the
  699. X * sizes with the size of the various fields in 'nocol.h'. Leave space for
  700. X * the 'condition' string added at the end.
  701. X */
  702. X/*                        1         2         3         4         5         6         7         8         9         0         1         2 */
  703. X/*               123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789. */
  704. X#define EHDR    "         Site      Address      Date  Time   +- Sender -+  +-- Variable --+ +- Value-+  + Thres -+    Units  Flags  Condition "
  705. X/*               +++++++++|++++  +++++++++|+++++ ++/++ ++:++  +++++++++|++  +++++++++|++++++ +++++++++|  +++++++++|  ++++++++  +++   END */
  706. X#define EFMT     "%14.14s  %-15.15s %02d/%02d %02d:%02d  %-12.12s  %16.16s %10lu  %10lu  %8.8s  %03o   "    /* Condition added at end */
  707. X#define EFIELDS v.site.name, v.site.addr, v.mon,v.day,v.hour,v.min, v.sender, v.var.name, v.var.value, v.var.threshold, v.var.units, v.nocop
  708. X
  709. X/*               123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789. */
  710. X#define SHDR    "         Site      Address      Time   +-Variable-+ +-Value-+  Condition  "
  711. X/*               +++++++++|++++  +++++++++|+++++ ++/++  +++++++++|++ ++++++++    END */
  712. X#define SFMT    "%14.14s  %-15.15s %02d:%02d  %12.12s %8lu    "  /* 62 chars */
  713. X#define SFIELDS    v.site.name, v.site.addr, v.hour, v.min, v.var.name, v.var.value
  714. X
  715. X
  716. X/*
  717. X * Define types of user responses for get_reply()
  718. X */
  719. X#define C_ANY        0x0    /* Any character (printable or non-) */
  720. X#define C_ALPHA        0x1    /* A-z */
  721. X#define C_DIGIT        0x2    /* 0-9 */
  722. X#define C_SPACE        0x4    /* SPACE, TAB */
  723. X#define C_PUNCT        0x8    /* All punctuation characters */
  724. X
  725. X/*
  726. X * These are usually defined in sys/file.h.  Needed for flock
  727. X */
  728. X#ifndef LOCK_SH
  729. X# define   LOCK_SH   1    /* shared lock */
  730. X# define   LOCK_EX   2    /* exclusive lock */
  731. X# define   LOCK_NB   4    /* don't block when locking */
  732. X# define   LOCK_UN   8    /* unlock */
  733. X#endif    /* LOCK_SH */
  734. X
  735. END_OF_FILE
  736.   if test 7298 -ne `wc -c <'nocol-3.0/src/include/netmon.h'`; then
  737.     echo shar: \"'nocol-3.0/src/include/netmon.h'\" unpacked with wrong size!
  738.   fi
  739.   # end of 'nocol-3.0/src/include/netmon.h'
  740. fi
  741. if test -f 'nocol-3.0/src/netmon/build_display.c' -a "${1}" != "-c" ; then 
  742.   echo shar: Will not clobber existing file \"'nocol-3.0/src/netmon/build_display.c'\"
  743. else
  744.   echo shar: Extracting \"'nocol-3.0/src/netmon/build_display.c'\" \(7182 characters\)
  745.   sed "s/^X//" >'nocol-3.0/src/netmon/build_display.c' <<'END_OF_FILE'
  746. X/*
  747. X * $Header: /home/aggarwal/lsrc/nocol/src/netmon/RCS/build_display.c,v 1.8 1993/10/30 03:52:08 aggarwal Exp $
  748. X */
  749. X
  750. X/* Copyright 1992 JvNCnet, Princeton */
  751. X
  752. X/*+ 
  753. X** It builds the 'display' screen by calling routines which write to the
  754. X** various windows (wmsg, whdr, wtitle, wprompt).
  755. X**
  756. X**    1) smile
  757. X**    2) display static data
  758. X**    3) event display
  759. X**    4) msgs display
  760. X**    4) refresh
  761. X**    5) poll and parse user input
  762. X**    6) never return
  763. X**
  764. X** displaying the messages needs a small trick - in the debug mode,
  765. X** the new mesage would overwrite the previous message because the
  766. X** debug message was writing independent of a file.
  767. X** Thus I used 'msg_on' which is a small toggle. The variable is
  768. X** turned off in 'msg_dpy()' at the end of all the files. The function
  769. X** is then not called by build_display() right away, but it is called
  770. X** after one skip. Seems to be a bit muddly, but pretty effective.
  771. X**
  772. X** RETURN VALUES
  773. X**
  774. X**    -1 on severe error.
  775. X**
  776. X**/
  777. X
  778. X/*+ 
  779. X *
  780. X *    $Log: build_display.c,v $
  781. X * Revision 1.8  1993/10/30  03:52:08  aggarwal
  782. X * Now uses dirent(). Deleted include dir.h
  783. X *
  784. X * Revision 1.7  1992/06/18  21:02:56  aggarwal
  785. X * Cleaned up for releasing.
  786. X *
  787. X *
  788. X * Revision 1.3  1990/05/23  17:19:44  aggarwal
  789. X * Added msg_on so that the function 'msg_dpy()' is skipped once
  790. X * after displaying all the files.
  791. X *
  792. X * Revision 1.1  90/03/09  13:04:36  aggarwal
  793. X * Initial revision
  794. X * 
  795. X */
  796. X
  797. X#include     "netmon.h"
  798. X
  799. X
  800. X#define WFULL(w)      (w->_cury == (w->_maxy - 1)) ? 1:0
  801. X
  802. Xbuild_display ()
  803. X{
  804. X    extern struct allwins aw;            /* defined in netmon.h    */
  805. X    extern int level, options, page;        /* defined in netmon.h    */
  806. X    extern int msg_on ;                /* defined in netmon.h    */
  807. X
  808. X    for (; ;)
  809. X    {
  810. X    hdr_dpy(aw.whdr);            /* display header    */
  811. X    msgtitle_dpy(aw.wmsgtitle);        /* display msg title    */
  812. X    if (event_dpy() == -1)            /* resets page number    */
  813. X      return(-1);
  814. X    title_dpy (aw.wtitle, page);        /* variable page number    */
  815. X    ++page ;                  /* increase after displaying */
  816. X    if (msg_on)                /* reset in msg_dpy()    */
  817. X    {
  818. X        if (msg_dpy() == -1)
  819. X          return(-1);
  820. X    }
  821. X    else
  822. X      msg_on = 1 ;                /* Turn it on        */
  823. X
  824. X    if (display_screenful() == -1)              /* display */
  825. X      return (-1);
  826. X
  827. X    parse_input(poll_input());         /* process user input     */
  828. X    }                        /* end:  endless for    */
  829. X}                               /* end: build_display    */
  830. X
  831. X
  832. X/***********************  FUNCTIONS  ***********************************/
  833. X
  834. X/*+ 
  835. X** The following functions write static information to the various 
  836. X** windows.
  837. X**/
  838. X
  839. Xtitle_dpy(wtitle,screen)            /* Main title        */
  840. X     WINDOW *wtitle;
  841. X     int screen;                /* to show screen num    */
  842. X{
  843. X    char    ptime[27];            /* present time        */
  844. X    time_t    stamp ;                /* time stamp        */
  845. X
  846. X    stamp = time ((time_t *)0) ;
  847. X    strncpy (ptime, ctime ((long *)&stamp), 26);
  848. X
  849. X    mvwprintw (wtitle, 0, 0, "%-3.2d", screen);
  850. X    mvwprintw (wtitle, 0, (int)(COLS/2 - 8), "%s", "JvNCnet NOCOL");
  851. X    mvwprintw (wtitle, 0, (int)(COLS - 30), "%26s", ptime);
  852. X    return(0);
  853. X}                        /* end:  title_dpy    */
  854. X
  855. X
  856. Xhdr_dpy(whdr)                    /* field headers    */
  857. X     WINDOW *whdr ;
  858. X{
  859. X    extern int    options ;
  860. X
  861. X    if (options & emode)            /* extended mode    */
  862. X      mvwprintw (whdr, 0, 0, EHDR);
  863. X    else
  864. X      mvwprintw (whdr, 0, 0, SHDR);        /* short header        */
  865. X    return(0) ;
  866. X}                        /* end:  hdr_dpy    */
  867. X
  868. Xmsgtitle_dpy(wmsgtitle)                /* Messages title    */
  869. X     WINDOW *wmsgtitle ;
  870. X{
  871. X    extern bool frozen ;            /* in netmon.h        */
  872. X    extern int  isdefined_pattern;        /* in read_filter.c */
  873. X    extern char pattern[] ;            /* in read_filter.c */
  874. X
  875. X    wmove(wmsgtitle, 0, 0) ;
  876. X    if (frozen)                           /* on first line of win    */
  877. X    {                            /* in reverse video    */
  878. X    wstandout (wmsgtitle);
  879. X    wprintw (wmsgtitle, "SCREEN FROZEN") ;
  880. X    wstandend (wmsgtitle);
  881. X    }
  882. X    else
  883. X      wclrtoeol (wmsgtitle) ;            /* erase line        */
  884. X
  885. X    /*
  886. X     * display the pattern after the 'screen locked' message (about 20 chars
  887. X     * long). The show_display_level should overwrite in case this gets too
  888. X     * long to display.
  889. X     */
  890. X    if (isdefined_pattern)
  891. X    {
  892. X    mvwprintw(wmsgtitle, 0, (int)max(COLS/4,  20), "FILTER ON: ") ;
  893. X    wprintw (wmsgtitle, "%.*s..", COLS/2, pattern);
  894. X    }
  895. X
  896. X    wclrtoeol (wmsgtitle) ;            /* erase rest of line    */
  897. X
  898. X    show_display_level(wmsgtitle, level);    /* on first line of win    */
  899. X    mvwprintw (wmsgtitle, 1, (int)(COLS/2 - 4), "MESSAGES");
  900. X    return(0) ;
  901. X}                        /* end:  msgtitle_dpy    */
  902. X
  903. X/*+         show_display_level
  904. X** FUNCTION:
  905. X**     Write out the display level in the first line in the message
  906. X** title window for information.
  907. X**/
  908. X
  909. Xshow_display_level(wmsgtitle,level)        /* on first line of win    */
  910. X     WINDOW *wmsgtitle;
  911. X     int level;
  912. X{
  913. X    mvwprintw (wmsgtitle, 0, COLS - 25, "  Display Level: ");
  914. X    if (level == E_CRITICAL)
  915. X      wprintw (wmsgtitle, "%-8.8s", "CRITICAL");
  916. X    else if (level == E_ERROR)
  917. X      wprintw (wmsgtitle,  "%-8.8s", "ERROR");
  918. X    else if (level == E_WARNING)
  919. X      wprintw (wmsgtitle,  "%-8.8s", "WARNING");
  920. X    else if (level == E_INFO)
  921. X      wprintw (wmsgtitle,  "%-8.8s", "INFO");
  922. X    else
  923. X      wprintw (wmsgtitle,  "%-8.8s", "UNKNOWN");
  924. X    wclrtoeol (wmsgtitle) ;
  925. X    return(0); 
  926. X}                        /* end:  show_dpy_level    */
  927. X
  928. X/*
  929. X * Display the prompts
  930. X */
  931. Xaprompt_dpy (wprompt)        /* Prompt at end of a full screen    */
  932. X     WINDOW *wprompt;
  933. X{
  934. X    mvwprintw (wprompt, 1, 0, PROMPTA);        /* blank line above    */
  935. X    wclrtoeol (wprompt);
  936. X    return(0);
  937. X}                        /* end: aprompt_dpy    */
  938. X
  939. Xbprompt_dpy (wprompt)       /* Prompt after displaying all files        */
  940. X     WINDOW *wprompt ;
  941. X{
  942. X    mvwprintw (wprompt, 1, 0, PROMPTB);        /* blank line above    */
  943. X    wclrtoeol (wprompt);
  944. X    return(0) ;
  945. X}                        /* end: bpromt_dpy    */
  946. X
  947. X/*+         display_screenful
  948. X**
  949. X** FUNCTION
  950. X**
  951. X**    Display screen of 'wmain' on the terminal. Forces cursor
  952. X** location by setting wmain's current location to that of the
  953. X** prompt windows current location.
  954. X**
  955. X** I tried a lot of variations (all logical according to me) on the
  956. X** screen update part - like get rid of touchwin() and call
  957. X** refresh(promptw) at the end and enable leaveok() etc. Tried it
  958. X** between BSD + Ultrix + Sun, and the 'subtle' differances forced me
  959. X** to add touchwin()  and  force the cursor location be turning
  960. X** leaveok off + moving the current wmain location to the actual
  961. X** wprompt location.
  962. X**
  963. X**/
  964. X
  965. Xdisplay_screenful ()
  966. X{
  967. X    extern struct allwins aw;        /* defined in netmon.h        */
  968. X    extern int options ;
  969. X
  970. X    int x, y ;                    /* To move the cursor    */
  971. X    if (WFULL(aw.wevent))
  972. X      aprompt_dpy(aw.wprompt);            /* display full  prompt    */
  973. X    else
  974. X      bprompt_dpy(aw.wprompt);            /* display help prompt    */
  975. X
  976. X    if (options & debug)
  977. X    {
  978. X    wprintw(aw.wmsg,
  979. X        "\n(DEBUG): frozen = %s, options = 0x%x\n", 
  980. X        frozen ? "YES" : "NO", options);
  981. X    wprintw(aw.wmsg,        
  982. X        "(DEBUG): Term= %s, LINES= %d, COLS= %d, Datadir= %s", ttytype,
  983. X        LINES, COLS, datadir) ;         /* ttytype in curses.h */
  984. X    wclrtoeol(aw.wmsg);
  985. X    }
  986. X    
  987. X    /*
  988. X     * Am calling touchwin() since its foolproof (see discussion above)
  989. X     */
  990. X    touchwin (aw.wmain);
  991. X    y = aw.wprompt->_cury + aw.wprompt->_begy ;    /* force cursor loc..    */
  992. X    x = aw.wprompt->_curx + aw.wprompt->_begx ;    /* ..to prompt window */
  993. X    wmove(aw.wmain, y, x);
  994. X    wrefresh (aw.wmain);            /* Onto screen */
  995. X    return (0) ;
  996. X}            /*** end:    display_screenful  ***/
  997. END_OF_FILE
  998.   if test 7182 -ne `wc -c <'nocol-3.0/src/netmon/build_display.c'`; then
  999.     echo shar: \"'nocol-3.0/src/netmon/build_display.c'\" unpacked with wrong size!
  1000.   fi
  1001.   # end of 'nocol-3.0/src/netmon/build_display.c'
  1002. fi
  1003. if test -f 'nocol-3.0/src/netmon/netmon.c' -a "${1}" != "-c" ; then 
  1004.   echo shar: Will not clobber existing file \"'nocol-3.0/src/netmon/netmon.c'\"
  1005. else
  1006.   echo shar: Extracting \"'nocol-3.0/src/netmon/netmon.c'\" \(7531 characters\)
  1007.   sed "s/^X//" >'nocol-3.0/src/netmon/netmon.c' <<'END_OF_FILE'
  1008. X/*+
  1009. X**    $Header: /home/aggarwal/lsrc/nocol/src/netmon/RCS/netmon.c,v 2.1 1993/10/30 03:53:11 aggarwal Exp $
  1010. X*/
  1011. X
  1012. X/* Copyright 1993 JvNCnet, Global Enterprise Services */
  1013. X
  1014. X/*
  1015. X**
  1016. X** To DISPLAY the output from various NOCOL monitoring programs.
  1017. X** Uses curses for screen management and display.
  1018. X**
  1019. X** The design of the program is such that it displays ALL the files in
  1020. X** the DATA directory one after another in a cycle. As an option , the
  1021. X** data directory can be displayed on the command line.
  1022. X**
  1023. X** A separate window for the events and another for the messages are
  1024. X** created. The message window can scroll and is for sending debug or
  1025. X** any other messages that might be needed in the future. A separate
  1026. X** routine 'msg_dpy' is called for the message 's display.
  1027. X**
  1028. X** AUTHOR:
  1029. X**
  1030. X**    Vikas Aggarwal            vikas@nisc.jvnc.net
  1031. X**
  1032. X*/
  1033. X
  1034. X/*  Copyright 1992 JvNCnet
  1035. X
  1036. X Permission to use, copy, modify and distribute this software and its
  1037. X documentation for any purpose is hereby granted without fee, provided that
  1038. X the above copyright notice appear in all copies and that both that copyright
  1039. X notice and this permission notice appear in supporting documentation, and
  1040. X that the name of JvNCnet not be used in advertising or publicity pertaining
  1041. X to distribution of the software without specific, written prior permission.
  1042. X JvNCnet makes no representations about the suitability of this software for
  1043. X any purpose.  It is provided "as is" without express or implied warranty.
  1044. X
  1045. X JvNCnet DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  1046. X IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL JvNCnet
  1047. X BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUDING DAMAGES RESULTING FROM LOSS
  1048. X OF USE, DATA OR PROFITS, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  1049. X OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1050. X*/
  1051. X
  1052. X/*
  1053. X * $Log: netmon.c,v $
  1054. X * Revision 2.1  1993/10/30  03:53:11  aggarwal
  1055. X * Fixed the definitions of the signal handlers
  1056. X *
  1057. X * Revision 2.0  1992/06/18  21:05:21  aggarwal
  1058. X * Additional features for releasing:
  1059. X *     o window resizing
  1060. X *     o terminal setup
  1061. X *
  1062. X * Revision 1.8  1992/05/14  12:34:41  aggarwal
  1063. X * Number of major fixes:
  1064. X *     - moved get_reply() to above main so types were defined
  1065. X *       before being called in 'main()'
  1066. X *     - setuserenviron() sprintf was missing terminal '\0'
  1067. X *     - set_terminal() extensively modified.
  1068. X *
  1069. X * Revision 1.4  1990/04/05  17:47:02  aggarwal
  1070. X * Was doing a 'endwin()' in Error even though initscr() had not been
  1071. X * called. Got rid of that. Extended the help a bit.
  1072. X *
  1073. X * Revision 1.1  90/03/09  13:06:18  aggarwal
  1074. X * Initial revision
  1075. X * 
  1076. X */
  1077. X#ifndef lint
  1078. X static char rcsid[] = "$RCSfile: netmon.c,v $ $Revision: 2.1 $ $Date: 1993/10/30 03:53:11 $" ;
  1079. X#endif
  1080. X
  1081. X/*+ 
  1082. X ** INCLUDES
  1083. X */
  1084. X
  1085. X#include    "netmon.h"            /* application specific    */
  1086. X
  1087. X/*
  1088. X * global variables
  1089. X */
  1090. Xchar *good_terminals[] = { GOODTERMINALS, "" } ;
  1091. Xchar *bad_terminals[] =  { BADTERMINALS,  "" } ;
  1092. X
  1093. Xmain (ac, av)
  1094. X     int    ac;
  1095. X     char    **av;
  1096. X{
  1097. X    extern     char *prognm;            /* defined in netmon.h    */
  1098. X    extern     int level, options;        /* defined in netmon.h    */
  1099. X    extern     char *optarg;
  1100. X    extern     int optind;
  1101. X    register     int i ;                /* temporary counter    */
  1102. X    void    done(), wsizechange();        /* for signals        */
  1103. X
  1104. X
  1105. X    /*
  1106. X     * Set the initial values of variables
  1107. X     */
  1108. X    prognm = av[0] ;                /* program name        */
  1109. X    datadir = DATADIR ;
  1110. X    msgsdir = MSGSDIR ;
  1111. X    helpfile = HELPFILE ;
  1112. X    eventsz = 0;                /* Init value important    */
  1113. X    page = 1;                    /* init value */
  1114. X    level = E_CRITICAL;                /* default severity    */
  1115. X
  1116. X    while ((i = getopt(ac, av, "dewl:q")) != EOF)
  1117. X      switch (i)
  1118. X      {
  1119. X       case 'd':
  1120. X      options = options | debug ;            /* debug option */
  1121. X      break ;
  1122. X       case 'w':
  1123. X       case 'e':                   /* expanded/wide  display */
  1124. X      options = options | emode;
  1125. X      break;
  1126. X       case 'l':                    /* level    */
  1127. X      sscanf(optarg, "%d", &level) ;
  1128. X      break;
  1129. X       case 'q':
  1130. X      options = options | quiet ;
  1131. X      break ;
  1132. X       case '?':
  1133. X       default:
  1134. X      fprintf(stderr, "%s: unknown flag: %c\n", prognm, i);
  1135. X      goto Error ;
  1136. X      }            /* end   switch        */
  1137. X
  1138. X    switch ( ac - optind )
  1139. X    {
  1140. X     case 0:                    /* default data dir */
  1141. X    break ;
  1142. X     case 1:
  1143. X    datadir = av[optind] ;            /* alternate data dir */
  1144. X    break ;
  1145. X     default:
  1146. X    goto Error;                /* more than one data dir */
  1147. X    }
  1148. X
  1149. X    /*
  1150. X     * Setup to catch ALL signals except SIGUSR1/SIGUSR2 for security
  1151. X     * purposes.
  1152. X     */
  1153. X    for (i = 0 ; i < SIGUSR1 ; ++i )
  1154. X      signal (i, done);
  1155. X
  1156. X    if (setuserenviron () == -1)    /* check the user environment    */
  1157. X    {                    /* .. specifically for TERM    */
  1158. X    perror ("setuserenv");
  1159. X    exit (1);
  1160. X    }
  1161. X
  1162. X    all_doer();                /* the main do'er    */
  1163. X
  1164. X    if (entered_curses)
  1165. X      endwin ();            /* This point never reached */
  1166. X    perror (prognm);
  1167. X    exit (1);            
  1168. X
  1169. X  Error:
  1170. X    usage ();                    /* No 'endwin' here */
  1171. X    exit (1);
  1172. X}                        /* end    'main'    */
  1173. X
  1174. X
  1175. X/*+         usage
  1176. X** FUNCTION
  1177. X**    Display short message on usage of the program
  1178. X**/
  1179. X
  1180. X#ifndef Fprintf
  1181. X#define Fprintf(s)    fprintf(stderr, (s) )
  1182. X#endif
  1183. X
  1184. Xusage()
  1185. X{
  1186. X    static char 
  1187. X      usage[]="[-d (debug)] [-q (quiet)] [-l level] [-w (wide)] [data dir]";
  1188. X    fprintf (stderr, "\nUSAGE: %s  %s\n\n", prognm, usage);
  1189. X    fprintf(stderr, "Data directory is: %s\n", datadir);
  1190. X    Fprintf("To verify terminal type, turn debug mode on and\n");
  1191. X    Fprintf("then toggle between wide display mode (using w)\n\n");
  1192. X    return (0);
  1193. X}        /* end usage()    */
  1194. X
  1195. X/*+         wsizechange
  1196. X ** FUNCTION:
  1197. X **     Function to catch window size change signals (in xterm, etc.)
  1198. X ** After getting the signal, the system blocks all further occurences of
  1199. X ** the signal until the function returns. However, if calling all_doer,
  1200. X ** this function never really returns, but calls all_doer() directly.
  1201. X ** So remember to unblock the SIGWINCH in case calling all_doer directly.
  1202. X **/
  1203. Xvoid  wsizechange()
  1204. X{
  1205. X#ifdef TIOCGWINSZ
  1206. X    static struct winsize win ;             /* 4.3 BSD window sizing */
  1207. X#endif
  1208. X
  1209. X#ifdef TIOCGWINSZ
  1210. X    if (ioctl(1, TIOCGWINSZ, (char *) &win) == 0 )
  1211. X    {
  1212. X        if (win.ws_row > 0)
  1213. X      LINES = win.ws_row ;
  1214. X        if (win.ws_col > 0)
  1215. X      COLS = win.ws_col ;
  1216. X    }
  1217. X#endif
  1218. X
  1219. X    if (entered_curses)
  1220. X    {
  1221. X    endwin() ;            /* get out of curses and start over */
  1222. X    tputs(clscr, 1, outchar);    /* clear the screen */
  1223. X    fflush(stdout);
  1224. X    }
  1225. X
  1226. X    /*
  1227. X     *  Now reset any special variables for setup_display() and return.
  1228. X     *  If calling 'all_doer' (doesn't return), remember to reset signal
  1229. X     */
  1230. X    eventsz = 0 ;            /* so that new size is reset */
  1231. X    setup_display() ;
  1232. X    display_screenful() ;        /* put stuff back on screen */
  1233. X
  1234. X}        /* end wsizechange */
  1235. X
  1236. X
  1237. X/*+         all_doer
  1238. X** FUNCTION:
  1239. X**     This is the main doer. It creates all the necessary windows
  1240. X** and then repeatedly calls the 'build_display()' routine to display
  1241. X** all the data. This is made as a separate routine from main so that
  1242. X** options can be changed and this function can be called directly
  1243. X** without going thru main() again.
  1244. X**/
  1245. X
  1246. Xall_doer()
  1247. X{
  1248. X    entered_curses = 1 ;        /* so done can call endwin() */
  1249. X
  1250. X#ifdef SIGWINCH                     /* catch window size change signals */
  1251. X    if (signal(SIGWINCH, wsizechange) == (void *)-1)
  1252. X      perror("couldn't set signal for SIGWINCH- ");
  1253. X#endif
  1254. X
  1255. X    setup_display();            /* Just creates all the windows    */
  1256. X    return (build_display());        /* Display all files forever    */
  1257. X
  1258. X}    /* end:  all_doer()  */
  1259. X
  1260. X
  1261. X/*+         done
  1262. X** FUNCTION
  1263. X**    Close up and die.
  1264. X**/
  1265. X
  1266. Xvoid done()
  1267. X{
  1268. X    echo();
  1269. X    if (entered_curses)            /* else kills the login window */
  1270. X      endwin();
  1271. X    printf ("\n\n");
  1272. X    exit(0);
  1273. X}
  1274. X
  1275. END_OF_FILE
  1276.   if test 7531 -ne `wc -c <'nocol-3.0/src/netmon/netmon.c'`; then
  1277.     echo shar: \"'nocol-3.0/src/netmon/netmon.c'\" unpacked with wrong size!
  1278.   fi
  1279.   # end of 'nocol-3.0/src/netmon/netmon.c'
  1280. fi
  1281. if test -f 'nocol-3.0/src/perlnocol/snmp-modemmon' -a "${1}" != "-c" ; then 
  1282.   echo shar: Will not clobber existing file \"'nocol-3.0/src/perlnocol/snmp-modemmon'\"
  1283. else
  1284.   echo shar: Extracting \"'nocol-3.0/src/perlnocol/snmp-modemmon'\" \(7440 characters\)
  1285.   sed "s/^X//" >'nocol-3.0/src/perlnocol/snmp-modemmon' <<'END_OF_FILE'
  1286. X#!/usr/local/bin/perl 
  1287. X# $Header: /home/aggarwal/lsrc/nocol/src/perlnocol/RCS/snmp-modemmon,v 1.1 1993/10/30 04:07:19 aggarwal Exp $
  1288. X#
  1289. X#        SNMPmodemmon - perl monitor for modem line's usage on Terminal Servers
  1290. X#
  1291. X#  -Vikas Aggarwal, vikas@jvnc.net, from code written by John Wobus, 
  1292. X#    jmwobus@mailbox.syr.edu
  1293. X#
  1294. X#  THIS IS AN SNMP VERSION OF THE modemmon  PROGRAM. IT USES the
  1295. X#  CMU-SNMP 'snmpwalk' program.
  1296. X#
  1297. X#####################
  1298. X# To Install:
  1299. X#
  1300. X#    Compile the CMU-SNMP programs and install snmpwalk and the
  1301. X#    mib.txt file in desired locations. Then set the variables
  1302. X#    as described in the 'Customize' section.
  1303. X#
  1304. X# Modemmon  reads a list of cisco terminal servers to monitor (from
  1305. X# a config file) and thresholds. It then logs into the cisco's and
  1306. X# counts the number of lines in use. When the used lines exceeds the
  1307. X# thresholds, the lines are displayed in NOCOL data format.
  1308. X#
  1309. X# Files used:
  1310. X#   snmpwalk -        From CMU-SNMP distribution
  1311. X#   mib.txt  -        MIB file in ASN syntax with merged Cisco MIB.
  1312. X#
  1313. X# Nocol event elements used:
  1314. X#   sender                     "modemmon"
  1315. X#   severity                   as read from the config file
  1316. X#   site
  1317. X#    name                      the cisco name
  1318. X#    addr                      cisco IP address
  1319. X#   var                       
  1320. X#    name                      "ModemLines"
  1321. X#    value                     1 means at Info level
  1322. X#    threshold                 as read from the config file
  1323. X#    units                     always "Usage"
  1324. X#
  1325. X## 
  1326. X##
  1327. X#
  1328. X############################
  1329. X## Variables customization #  overrides values in the nocollib.pl library
  1330. X############################
  1331. X$SNMP = "../cmu-snmp" ;            # To find binary and MIBFILW
  1332. X$prog =  "$SNMP/bin/snmpwalk" ;        # location of 'snmpwalk'
  1333. X$mibfile = "$SNMP/mib.txt" ;    # Location of MIB file
  1334. X
  1335. X# Cisco MIB ASN
  1336. X# cisco.local...tsLineActive = 9.2.9.2.1.1
  1337. X$mibcisco  = ".iso.org.dod.internet.private.enterprises.cisco.local" ;
  1338. X$miblineactive = $mibcisco.".lts.ltsLineTable.ltsLineEntry.tsLineActive" ;
  1339. X$miblinetype = $mibcisco.".lts.ltsLineTable.ltsLineEntry.tsLineType" ;
  1340. X
  1341. X$community=  "public";
  1342. X
  1343. X$varname="ModemLines";
  1344. X$varunits="Usage" ;            # the var.units field in EVENT struct
  1345. X$sleepint=60*5;                   # Seconds to sleep between tries.
  1346. X############################
  1347. X$debug = 0;                # set to 1 for debugging output
  1348. X$libdebug = 0;                # set to 1 for debugging output
  1349. X
  1350. Xrequire  "nocollib.pl" ;
  1351. X
  1352. X-x $prog || die("Could not find executable $prog, exiting");
  1353. X-f $mibfile || die("Could not find MIB file $rprog, exiting");
  1354. X$ENV{"MIBFILE"}= $mibfile ;
  1355. X
  1356. X@me=split(/\//,$0); $me=pop(@me);
  1357. X#$piddir=join("/",@me); if ($piddir eq "") {$piddir=$etcdir;}
  1358. X$piddir=$etcdir;
  1359. X$cfile="$etcdir/$me-confg";
  1360. X$datafile="$datadir/$me-output";
  1361. X
  1362. X$sender= $me ;                # filled in the EVENT sender
  1363. X
  1364. X
  1365. X##
  1366. X# Read the config file. Use '\t' as a separator for 'item'
  1367. Xsub readconf {
  1368. X    local ($nets, $interface, $zone) ;
  1369. X
  1370. X    open(CONFIG,"<$cfile")||die("Couldn't find $cfile, exiting");
  1371. X    while(<CONFIG>)
  1372. X    {
  1373. X    chop;
  1374. X    if(/^\s*#/) {next;}   # skip comments
  1375. X    if(/^\s*$/) {next;}   # skip blank lines
  1376. X    if (/\s*(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s*$/)
  1377. X    {
  1378. X        $item="$1\t$2" ;     # the name and address
  1379. X        $wlevel{$item} = $3; # Warning level
  1380. X        $elevel{$item} = $4; # Error level
  1381. X        $clevel{$item} = $5; # Critical level
  1382. X        push(@items,$item);
  1383. X    }
  1384. X    else {print "Ignoring illegal line: $_\n";}
  1385. X
  1386. X    }    # end while(CONFIG)
  1387. X
  1388. X    close(CONFIG);
  1389. X    if(0>$#items){die("Nothing to monitor in $cfile, exiting")};
  1390. X    if ($debug) {
  1391. X    print "Items are:\n"; foreach (@items) { print "\t$_\n" } ;
  1392. X    }
  1393. X}                # end: readconf
  1394. X
  1395. X
  1396. X# 
  1397. X## Check state of each router
  1398. X##
  1399. X#
  1400. X# Walks the TServer ltsLineActive/ltsLineType  mib trees (cisco specific) 
  1401. X# and collects TERMINAL type lines that are ACTIVE.
  1402. X# Prints number of active lines and total number of TTY lines.
  1403. X# Prints '-1' on error.
  1404. X#
  1405. X# CAVEATS:
  1406. X#   - Walking entire mib tree over UDP can be iffy. This is tested by seeing
  1407. X#     if any responses are missing in the TYPE list and the ACTIVE list.
  1408. X#
  1409. X###    
  1410. X#
  1411. Xsub dotest {
  1412. X    local ($router) = @_ ;
  1413. X    local ($acount, $tcount) = (0, 0) ;
  1414. X    local ($walkactive, $walktype, @active, @type) ;
  1415. X
  1416. X    if ($debug) { print "Checking $router\n"; }
  1417. X
  1418. X    -x $prog || die("Could not find executable $prog, exiting");
  1419. X
  1420. X    $walkactive = "$prog $router $community $miblineactive";
  1421. X    $walktype =   "$prog $router $community $miblinetype";
  1422. X    if ($debug) { 
  1423. X#    print "Active cmd= $walkactive\nType cmd= $walktype\n\n" ;
  1424. X    }
  1425. X#
  1426. X# Output of Check-active SNMP command is:
  1427. X#    Name: .iso.org.dod........lts.ltsLineTable.lts.LineEntry.tsLineActive.0
  1428. X#    INTEGER: 1
  1429. X
  1430. X    open (ACTIVE, "$walkactive |") || die "Can't check active lines.";
  1431. X    while(<ACTIVE>){
  1432. X    chop;
  1433. X    if (/^\s*INTEGER:\s*(\d+)\s*$/)
  1434. X    {
  1435. X        push(@active,$1);
  1436. X#        if ($debug) { print "$1, "; }
  1437. X    }
  1438. X    }
  1439. X    close(ACTIVE);
  1440. X#    if ($debug) { print "\n"; }
  1441. X
  1442. X## Output of Check-Type SNMP command is:
  1443. X#    Name: .iso.org.dod........lts.ltsLineTable.lts.LineEntry.tsLineType.0
  1444. X#    INTEGER: console(2) OR terminal(3) OR virtual-terminal(5)
  1445. X
  1446. X    open (TYPE, "$walktype |") || die "Can't check line types.";
  1447. X    while(<TYPE>){
  1448. X    chop;
  1449. X    if (/^\s*INTEGER:\s*(\S(.*\S)?)\s*$/)
  1450. X    {
  1451. X        push(@type,$1);
  1452. X#        if ($debug == 2) { print "$1, "; }
  1453. X    }
  1454. X    }
  1455. X    close(TYPE);
  1456. X#    if ($debug) { print "\n"; }
  1457. X
  1458. X    if ($debug) { 
  1459. X    print "(debug): active list= $#active, type list= $#type\n" ;
  1460. X    }
  1461. X
  1462. X    if ($#active != $#type) 
  1463. X    { 
  1464. X    print "WARNING: active list len= $#active != type list len= $#type\n" ;
  1465. X    return (-1);
  1466. X    }
  1467. X
  1468. X    foreach $i (0..$#active)
  1469. X    {
  1470. X    $isterm = ($type[$i] =~ /terminal\(3\)/); # Search for TTY terminals
  1471. X    if($isterm) {
  1472. X        $tcount++;
  1473. X        $acount+=$active[$i]; # Since '$active' is either 0 or 1 anyway
  1474. X        if ($debug) { 
  1475. X        print "(debug): Index=$i Type=$type[$i] Active=$active[$i]\n";
  1476. X        }
  1477. X    }
  1478. X    }
  1479. X
  1480. X    if ($debug) {print "(debug)Active/Total terminals: $acount/$tcount\n"; }
  1481. X
  1482. X    return ($acount) ;
  1483. X
  1484. X}    # end &dotest()
  1485. X
  1486. X
  1487. X###
  1488. X### main
  1489. X###
  1490. X
  1491. X# Fork and get rid of old process.
  1492. Xif($p=fork){print "$p\n";exit;}
  1493. X&standalone($me,$piddir);
  1494. X
  1495. X&readconf ;
  1496. X
  1497. Xforeach $item (@items) {
  1498. X    local ($host, $addr) = split( /\t/, $item );
  1499. X    &init_event ($host, $addr, $item);
  1500. X}
  1501. X
  1502. Xwhile (1)
  1503. X{
  1504. X    foreach $item (@items) {
  1505. X    local ($host, $addr) = split( /\t/, $item );
  1506. X    local ($linesused) =  &dotest ($addr);
  1507. X
  1508. X    if ($linesused < 0)
  1509. X    {
  1510. X        print "$me: dotest failed for $host ($addr) , skipping\n";
  1511. X        next ;
  1512. X    }
  1513. X    if ($linesused >= $clevel{$item} ) # critical level
  1514. X    {
  1515. X        if ($debug) {print "(debug): Maxlevel is Critical\n";}
  1516. X        $varthres{$item} = $clevel{$item} ; # threshold
  1517. X        &update_event($item, 0, $linesused, $E_CRITICAL);
  1518. X    }
  1519. X    elsif ($linesused >= $elevel{$item} )
  1520. X    {
  1521. X        if ($debug) {print "(debug): Maxlevel is Error\n";}
  1522. X        $varthres{$item} = $elevel{$item} ; # threshold
  1523. X        &update_event($item, 0, $linesused, $E_ERROR);
  1524. X    }
  1525. X    elsif ($linesused >= $wlevel{$item} )
  1526. X    {
  1527. X        if ($debug) {print "(debug): Maxlevel is Warning\n";}
  1528. X        $varthres{$item} = $wlevel{$item} ; # threshold
  1529. X        &update_event($item, 0, $linesused, $E_WARNING);
  1530. X    }
  1531. X    else
  1532. X    {
  1533. X        if ($debug) {print "(debug): Level is INFO\n";}
  1534. X        $varthres{$item} = $wlevel{$item} ; # threshold is warning level
  1535. X        &update_event($item, 1, $linesused, $E_WARNING); # status UP
  1536. X    }    
  1537. X    }
  1538. X
  1539. X    ; ## Note: we want to write the file quickly.
  1540. X
  1541. X    open(OEVENTS,">$datafile");
  1542. X    foreach $item (@items) {
  1543. X    &writeevent($item);
  1544. X    }
  1545. X    close(OEVENTS);
  1546. X    sleep($sleepint);
  1547. X}
  1548. X
  1549. END_OF_FILE
  1550.   if test 7440 -ne `wc -c <'nocol-3.0/src/perlnocol/snmp-modemmon'`; then
  1551.     echo shar: \"'nocol-3.0/src/perlnocol/snmp-modemmon'\" unpacked with wrong size!
  1552.   fi
  1553.   chmod +x 'nocol-3.0/src/perlnocol/snmp-modemmon'
  1554.   # end of 'nocol-3.0/src/perlnocol/snmp-modemmon'
  1555. fi
  1556. if test -f 'nocol-3.0/src/pingmon/poll_sites.c' -a "${1}" != "-c" ; then 
  1557.   echo shar: Will not clobber existing file \"'nocol-3.0/src/pingmon/poll_sites.c'\"
  1558. else
  1559.   echo shar: Extracting \"'nocol-3.0/src/pingmon/poll_sites.c'\" \(7434 characters\)
  1560.   sed "s/^X//" >'nocol-3.0/src/pingmon/poll_sites.c' <<'END_OF_FILE'
  1561. X/*+    $Header: /home/aggarwal/lsrc/nocol/src/pingmon/RCS/poll_sites.c,v 1.18 1993/10/30 03:16:11 aggarwal Exp $
  1562. X *
  1563. X */
  1564. X
  1565. X/* Copyright 1992 JvNCnet, Princeton */
  1566. X
  1567. X/*+
  1568. X**
  1569. X** FUNCTION
  1570. X**
  1571. X**    This function pings all the sites and determines their status.
  1572. X**
  1573. X**    It reads the site info from the output file and after pinging it,
  1574. X**    writes the new status back in the file. It uses raw i/o.
  1575. X**
  1576. X**    If the status remains DOWN during the next test of the
  1577. X**    site, it raises the severity (it polls 7 sites a minute)
  1578. X**
  1579. X**    Also, if previous status is same as present, it does not
  1580. X**    change the time of test (thus the time is the time that the 
  1581. X**    site has been at the current status - useful for any other
  1582. X**    program that needs to know status of the sites down).
  1583. X**
  1584. X**      Does one pass over the entire file, returns -1 if error.
  1585. X**
  1586. X**/
  1587. X
  1588. X/*
  1589. X *    $Log: poll_sites.c,v $
  1590. X * Revision 1.18  1993/10/30  03:16:11  aggarwal
  1591. X * Now uses the update_event() library call.
  1592. X *
  1593. X * Revision 1.17  1993/09/18  22:32:29  aggarwal
  1594. X * Added logging facilities.
  1595. X *
  1596. X * Revision 1.16  1992/06/18  21:14:17  aggarwal
  1597. X * Added code for 'multiping'. Also added macros for increasing
  1598. X * severity.
  1599. X *
  1600. X * Revision 1.15  1992/05/13  16:09:15  aggarwal
  1601. X * Changed the nocol.h struct so that addr is now a char[] instead of
  1602. X * inet_addr. Altered this file to match change.
  1603. X *
  1604. X * Revision 1.7  89/12/19  10:43:54  network
  1605. X * The location of 'ping' should be explicitly defined or else
  1606. X * the path should include '/etc' before calling the program
  1607. X * else the shell does not find 'ping' and all the sites show
  1608. X * down.
  1609. X * 
  1610. X * Revision 1.6  89/11/27  17:08:10  aggarwal
  1611. X * Added macro 'ESC_SEVERITY' to escalate the severity.
  1612. X * Shifted around the 'case DOWN' statements a bit since the
  1613. X * state was being changed before the 'if' test making it
  1614. X * kinda redundant.
  1615. X * 
  1616. X * Revision 1.1  89/11/08  12:09:55  aggarwal
  1617. X * Initial revision
  1618. X * 
  1619. X */
  1620. X
  1621. X/*+ 
  1622. X** INCLUDE FILES
  1623. X**/
  1624. X
  1625. X#include "pingmon.h"            /* program specific defines    */
  1626. X
  1627. X#include <signal.h>
  1628. X#include <sys/file.h>
  1629. X
  1630. Xstatic char pingcmd[BUFSIZ];            /* the ping command used */
  1631. Xstatic int  maxseverity = E_CRITICAL ;    /* Max severity of pingmon events */
  1632. X
  1633. X/* #defines for finish_status */
  1634. X#define REACHED_EOF 1
  1635. X#define READ_ERROR  2
  1636. X
  1637. Xpoll_sites(fdout)
  1638. X     int fdout;                /* Descriptors to open files    */
  1639. X{
  1640. X    extern int debug;            /* Enable debug (in pingmon.h)    */
  1641. X    static FILE *p_cmd;            /* for creating the ping cmd    */
  1642. X    static int batchsize = BATCHSIZE ;    /* num of sites to ping at a time */
  1643. X    EVENT v[BATCHSIZE];            /* described in nocol.h        */
  1644. X    char line[BUFSIZ];             /* to create the ping command    */
  1645. X    struct tm *ltime ;    
  1646. X    time_t locclock ;            /* careful: don't use 'long'    */
  1647. X    long status;                   /* site status            */
  1648. X    int sent, recv, bufsize;        /* recieved response        */
  1649. X    int i, numsites ;            /* actual number of sites read in */
  1650. X    int finish_status = 0;        /* why we stopped */
  1651. X
  1652. X    if ( lseek(fdout, (off_t)0, SEEK_SET) == -1)    /* rewind the file    */
  1653. X    {
  1654. X    perror (prognm);
  1655. X    return (-1);
  1656. X    }
  1657. X
  1658. X    while (!finish_status)        /* until end of all sites... */
  1659. X    {
  1660. X    char sites[BUFSIZ] ;        /* for list of sites to ping */
  1661. X    *sites = '\0' ;
  1662. X
  1663. X    /* try to read in as many sites as we can, up to batchsize */
  1664. X    for (numsites = 0; numsites < batchsize; numsites++)
  1665. X    {
  1666. X        bufsize = read(fdout, &v[numsites], sizeof(EVENT));
  1667. X        if (bufsize != sizeof(EVENT))
  1668. X        {
  1669. X        finish_status = bufsize ? READ_ERROR : REACHED_EOF;
  1670. X        break;
  1671. X        } 
  1672. X        else
  1673. X          strcat(strcat(sites, " "), v[numsites].site.addr);
  1674. X    }    /* end for */
  1675. X
  1676. X    if (!numsites)         /* means something bad happened, or EOF */
  1677. X      continue;        /* ...next while statement, finish_stat set */
  1678. X
  1679. X    /*
  1680. X     * The ping command for 'multiping' is different from the standard.
  1681. X     * Hence the 'ifdef'. It allows for the -t and -q options.
  1682. X     */
  1683. X
  1684. X#ifdef MULTIPING
  1685. X    /*
  1686. X     * multiping -q (quiet) -c <pkt count> -s <pkt size> -t (tabular) sites
  1687. X     *
  1688. X     * For tabular output, data is separated by a line, so use the
  1689. X     * sed command to chop off top portion.
  1690. X     */
  1691. X    /*
  1692. X     * the output from ping looks something like this:
  1693. X     *
  1694. X     *   PING 128.121.50.145 (128.121.50.145): 56 data bytes
  1695. X     *   PING 128.121.50.147 (128.121.50.147): 56 data bytes
  1696. X     *   PING 128.121.50.140 (128.121.50.140): 56 data bytes
  1697. X     *   
  1698. X     *   -=-=- PING statistics -=-=-
  1699. X     *                                         Number of Packets
  1700. X     *   Remote Site                     Sent    Rcvd    Rptd   Lost
  1701. X     *   -----------------------------  ------  ------  ------  ----
  1702. X     *   128.121.50.145                     10      10       0    0%
  1703. X     *   128.121.50.147                     10      10       0    0%
  1704. X     *   128.121.50.140                     10      10       0    0%
  1705. X     *   -----------------------------  ------  ------  ------  ----
  1706. X     *   TOTALS                             30      30       0    0%
  1707. X     *
  1708. X     * (I've cut off the right part of the screen to make it fit)
  1709. X     * the sed command below kills everything up to and including the
  1710. X     * first row of dashes ----
  1711. X     *
  1712. X     * The site name is printed as %30.30 (30 spaces)
  1713. X     */
  1714. X
  1715. X    sprintf(pingcmd, "%s -qtc %d -s %d %s | %s\0",
  1716. X        ping, NPACKETS, DATALEN, sites, "sed '1,/^-----/d'") ;
  1717. X
  1718. X#else /* if not MULTIPING */
  1719. X
  1720. X    /*
  1721. X     * A typical (standard) 'ping | tail -2' output looks like this:
  1722. X     *
  1723. X     * If you have a different style ping command format and output, then
  1724. X     * alter here.
  1725. X     *
  1726. X     *     r2d2-vikas> /usr/etc/ping -s nisc.jvnc.net 1000  5 | tail -2
  1727. X     *     5 packets transmitted, 5 packets received, 0% packet loss
  1728. X     *     round-trip (ms)  min/avg/max = 4/4/5
  1729. X     */
  1730. X    sprintf(pingcmd,"%s -s %s %d %d | %s\0",
  1731. X        ping, sites, DATALEN, NPACKETS, "tail -2" );
  1732. X
  1733. X#endif    /* ifdef MULTIPING */
  1734. X
  1735. X    if (debug)
  1736. X      fprintf(stderr, "(debug) %s: PINGCMD is\t%s\n", prognm, pingcmd) ;
  1737. X
  1738. X    if ((p_cmd = popen(pingcmd, "r")) == NULL)    /* open up the pipe */
  1739. X    {
  1740. X        perror("poll_sites (popen)");
  1741. X        return(-1);
  1742. X    }
  1743. X
  1744. X    /*
  1745. X     * 'multiping' produces output lines in the order in which they
  1746. X     * appeared in the command line, so we can just step thru the v[]
  1747. X     * array.
  1748. X     * After reading each line, update the corresponding event struct
  1749. X     */
  1750. X
  1751. X      for (i = 0; i < numsites; i++)
  1752. X      {
  1753. X      int n ;
  1754. X      n = fgetline(p_cmd, line, sizeof (line));
  1755. X#ifdef MULTIPING
  1756. X      /*
  1757. X       * The output after 30 characters has pkts sent and recieved
  1758. X       * Can't use '%*s' to skip over the sitename since sometimes
  1759. X       * the sitename gets truncated and we end up with two words.
  1760. X       * The '30' size is defined in the multiping program (yeah, so
  1761. X       * its a hack.)
  1762. X       */
  1763. X      sscanf(&line[30], "%*d %d", &recv);
  1764. X      status = (NPACKETS - recv) > PING_THRES ? 0 : 1 ;
  1765. X#else
  1766. X      /*
  1767. X       * Trying to scan line of the form:
  1768. X       *    10 packets transmitted, 1 packets received, 90% packet loss
  1769. X       *    round-trip (ms)  min/avg/max = 2/2/3
  1770. X       */
  1771. X
  1772. X      sscanf (line, "%d %*s %*s %d", &sent, &recv);
  1773. X      if (sent != NPACKETS)        /* Error of some sort */
  1774. X      {
  1775. X          recv = 0 ;
  1776. X          status = 0 ;
  1777. X      }
  1778. X      else
  1779. X        status = ((NPACKETS - recv) > PING_THRES) ? 0 : 1 ;
  1780. X#endif    /* MULTIPING */
  1781. X
  1782. X      update_event(&(v[i]), status, recv, maxseverity);
  1783. X
  1784. X      }            /* end for */
  1785. X
  1786. X    if (pclose(p_cmd) < 0)              /* close the pipe */
  1787. X      perror("poll_sites (pclose)");
  1788. X
  1789. X      /* rewind the file and write out the whole array */
  1790. X      lseek(fdout, -(off_t)(sizeof(EVENT) * numsites), SEEK_CUR);
  1791. X      write(fdout, (char *)v, sizeof(EVENT) * numsites);
  1792. X
  1793. X    }    /* end while (until end of all sites) */
  1794. X
  1795. X    return (finish_status != REACHED_EOF) ? -1 : 1;
  1796. X
  1797. X}    /* end poll_sites */
  1798. X
  1799. END_OF_FILE
  1800.   if test 7434 -ne `wc -c <'nocol-3.0/src/pingmon/poll_sites.c'`; then
  1801.     echo shar: \"'nocol-3.0/src/pingmon/poll_sites.c'\" unpacked with wrong size!
  1802.   fi
  1803.   # end of 'nocol-3.0/src/pingmon/poll_sites.c'
  1804. fi
  1805. if test -f 'nocol-3.0/src/support/mping/spqr.doc' -a "${1}" != "-c" ; then 
  1806.   echo shar: Will not clobber existing file \"'nocol-3.0/src/support/mping/spqr.doc'\"
  1807. else
  1808.   echo shar: Extracting \"'nocol-3.0/src/support/mping/spqr.doc'\" \(7029 characters\)
  1809.   sed "s/^X//" >'nocol-3.0/src/support/mping/spqr.doc' <<'END_OF_FILE'
  1810. XSPQR
  1811. X
  1812. XSuccessive Ping Quality Regression     (Okay, you think of a better name)
  1813. X
  1814. X
  1815. Xspqr is a tool which can spot "low intensity" problems in LAN or WAN
  1816. Xfunctioning.  Based on the venerable "ping" (ICMP_ECHO) facility, it
  1817. Xcontinuously monitors stations based on a configuration file and keeps
  1818. Xa cumulative problem metric averaged over 5, 15, and 60 minute intervals.
  1819. X
  1820. Xspqr consists of three parts: a driver/reporting program which initiaties
  1821. Xa poll every minute and averages the results, a parallel pinger program
  1822. X(which can send ICMP_ECHO packets to an arbitrarily large number of targets
  1823. Xin parallel), and a simple display program which continuously prints the
  1824. Xcurrent status to the screen.  The display program is suitable to run
  1825. Xas a restricted shell.
  1826. X
  1827. Xmping -- the parallel pinger program
  1828. X------------------------------------
  1829. XMping is driven from a configuration file (or standard input) which
  1830. Xlists the addresses to ping, and optionally:
  1831. X
  1832. X    packet length    (default 56 bytes of ICMP data)
  1833. X    packet data    (default all zeros)
  1834. X    # packets    (default 1)
  1835. X    # retries    (default 5)
  1836. X    retry interval    (default 1 second)
  1837. X
  1838. XThe format of the file is simple, consisting of two or three fields
  1839. Xfor each entry.  The fields are:
  1840. X
  1841. X    name    address    [options]
  1842. X
  1843. XIf given, <options> is one or more comma-separated fields in the order:
  1844. X
  1845. X    size,pattern,numToGet,retry,timeout
  1846. X
  1847. XThis parses option fields left to right, as indicated by commas.  Missing
  1848. Xor empty fields use the default value (see below).  For example, the
  1849. Xoption string to specify just the size (128) and pattern (0x15) would be
  1850. X"128,0x15": the remaining fields would default.  To specify a size (128)
  1851. Xand a retry count (2), the option field would be "128,,,2".  To specify
  1852. Xjust a timeout of 2 seconds, the option string would be ",,,,2000".
  1853. X
  1854. X
  1855. X size [default: 56]:        Decimal number giving the size of the ICMP
  1856. X                data portion of the packet.  The actual IP
  1857. X                packet will be at least 8 octets larger.
  1858. X
  1859. Xpattern [default: 0x0]:    A hex number specifying a byte value to
  1860. X                initialize the ICMP data portion of the
  1861. X                packet.
  1862. X
  1863. XnumToGet [default: 1]:    Number of return packets to require.
  1864. X
  1865. Xretry [default: 5]:        Number of retries to make before declaring
  1866. X                a packet lost.  Note that if <numToGet> is
  1867. X                greater than 1, the retry limit applies to
  1868. X                each attempt.  That is if the first attempt
  1869. X                requires 4 tries before a successful return,
  1870. X                then next attempt will still make up to 5
  1871. X                tries.
  1872. X
  1873. Xtimeout [default: 1000]    Number of milliseconds to wait before
  1874. X                assuming packet lost and retrying.  The
  1875. X                default timeout is fine within an all
  1876. X                ethernet environment, but you need a longer
  1877. X                one for WAN links.
  1878. X
  1879. XThe <name> field is not used for anything except producing the report.
  1880. X
  1881. XThe <address> field can be either an IP address in any of the notations
  1882. Xacceptable to the inet_addr() function, or it can be a domain name.
  1883. XIf a domain name is used, and the gethostbyname() function returns
  1884. Xmore than one address, it is treated like multiple configuration lines,
  1885. Xone for each address.  For example the configuration line:
  1886. X
  1887. X    NS-NIC    ns.nic.ddn.mil    56,0,2
  1888. X
  1889. Xis treated as if read:
  1890. X
  1891. X    NS-NIC    192.112.36.4    56,0,2
  1892. X    NS-NIC    192.67.67.53    56,0,2
  1893. X
  1894. X
  1895. Xbased on the configuration, the parallel pinger sends packets to every
  1896. Xtarget on the list, retrying as necessary until all targets have either
  1897. X(a) returned the required number of packets or (b) failed to return a
  1898. Xpacket in the specified number of timeouts.
  1899. X
  1900. XIt then reports for each target: how many packets sent, how many returned,
  1901. Xand the total packet round trip time (in microseconds) for all returned
  1902. Xpackets.
  1903. X
  1904. Xmsummary -- the driver program
  1905. X------------------------------
  1906. XThe driver program invokes mping once each cycle (default 60 seconds)
  1907. Xand reads its output to produce a summary of all targets showing less
  1908. Xthan perfect connectivity.   There are four columns of bad/RTT pairs,
  1909. Xand a single RPT column.  The bad/RTT pairs show the percentage of
  1910. Xdropped packets and the average round trip time for: (1) the most
  1911. Xrecent poll, (2) the most recent 5 polls, (3) the most recent 15 polls,
  1912. Xand (4) the most recent 60 polls.  Thus temporary problems eventually
  1913. Xget averaged out and dropped from the report, but persistent low-level
  1914. Xproblems remain prominent.
  1915. X
  1916. XThe "RPT" column shows what percentage of the time this system has been
  1917. Xreported.  A target is dropped from the report when all averages become
  1918. X0.  Thus a target with.
  1919. X
  1920. XHere is a sample report:
  1921. X
  1922. X------------------------------------------------------------------------------
  1923. X16:19:27    Iter: 16288 Cycle:  14   current    avg. 5   avg. 15   avg. 60
  1924. XSystem Name        IP Address      bad   RTT bad   RTT bad   RTT bad   RTT RPT
  1925. X------------------ --------------- --- ----- --- ----- --- ----- --- ----- ---
  1926. Xcupid              130.132.21.192    0   1.6   2   1.8  13   1.8  18   1.8  99
  1927. Xcalvin             130.132.21.195   33   1.2  27   1.4  23   1.4  18   1.4  98
  1928. Xdual               130.132.21.211    0   1.8  14   1.8  16   1.9  12   1.7  47
  1929. Xyaleads            130.132.21.130    0   3.9   0   4.2   0   4.6   1   5.2   8
  1930. Xcondor             130.132.21.141  100   0.0 100   0.0 100   0.0 100   0.0 100
  1931. Xvenus              130.132.1.5       0   5.4   0   5.5   2   5.6   7   5.8  94
  1932. Xbiomed.med         130.132.19.48     0   5.0   0   5.2   0   5.3   4   5.5  30
  1933. Xgucci.stat         130.132.16.16     0   3.7   0   4.0   1   4.0   6   4.0 100
  1934. Xhermes.stat        130.132.16.19   100   3.9 100   3.9 100   3.9  95   3.8 100
  1935. Xsysc.eng           130.132.20.240    0   4.2   0   4.2   0   4.3   1   4.3  19
  1936. Xcld3.eng           130.132.20.251    0   4.0   0   4.0   1   4.1   2   4.1   4
  1937. X74 entries skipped for all-0 error averages
  1938. X
  1939. X------------------------------------------------------------------------------
  1940. X
  1941. XThis report shows systems "condor" is dropping all packets, and has
  1942. Xbeen for the last 60 cycles.  "hermes.stat" has been dropping all
  1943. Xpackets for at least the last 15 cycles, but sometime in the last 60
  1944. Xcycles some packets got through.  (Both situations are consistent with
  1945. Xthe target machine being down).
  1946. X
  1947. XThe more interesting reports are for machines like venus, calvin, gucci.stat,
  1948. Xand cupid.  They all show persistent long-term drop rates, evidenced by the
  1949. Xhigh value in the "RPT" column.  In a LAN environment, nodes should show
  1950. Xa 0% packet drop rate virtually all the time.  An occasional dropped packet
  1951. Xis generally not anything to worry about.  Persistent non-zero drop rates
  1952. Xto certain nodes indicates an error condition either at the end nodes or
  1953. Xon a network segment somewhere between the station running SPQR and the
  1954. Xend nodes.  Running SPQR on several nodes on different segments is a good
  1955. Xway to "triangulate" in on a problem bridge or router.  Its first use
  1956. X(actually, reason for development) was to establish that a specific
  1957. Xethernet interface on a cisco router had a 1% packet drop rate that didn't
  1958. Xshow up in the SNMP data.
  1959. X
  1960. XThe "Iter" value in the heading is the number of iterations this driver
  1961. Xprogram has made; the "Cycle" value is how many seconds it takes to run
  1962. Xeach cycle.
  1963. END_OF_FILE
  1964.   if test 7029 -ne `wc -c <'nocol-3.0/src/support/mping/spqr.doc'`; then
  1965.     echo shar: \"'nocol-3.0/src/support/mping/spqr.doc'\" unpacked with wrong size!
  1966.   fi
  1967.   # end of 'nocol-3.0/src/support/mping/spqr.doc'
  1968. fi
  1969. if test -f 'nocol-3.0/src/tpmon/tpmon.c' -a "${1}" != "-c" ; then 
  1970.   echo shar: Will not clobber existing file \"'nocol-3.0/src/tpmon/tpmon.c'\"
  1971. else
  1972.   echo shar: Extracting \"'nocol-3.0/src/tpmon/tpmon.c'\" \(6824 characters\)
  1973.   sed "s/^X//" >'nocol-3.0/src/tpmon/tpmon.c' <<'END_OF_FILE'
  1974. X/*
  1975. X * $Header: /home/aggarwal/lsrc/nocol/src/tpmon/RCS/tpmon.c,v 1.5 1993/11/03 20:51:03 aggarwal Exp $
  1976. X *
  1977. X * tpmon.c -- contains the throughput() function.  See tpmon.h
  1978. X * for calling parameters.
  1979. X *
  1980. X * $Log: tpmon.c,v $
  1981. X * Revision 1.5  1993/11/03  20:51:03  aggarwal
  1982. X * Added ifdef for h_addr (defined in netdb.h) in case its defined.
  1983. X *
  1984. X * Revision 1.4  1993/10/30  03:29:29  aggarwal
  1985. X * Added code to auto detect if given an IP address instead of an
  1986. X * IP name.
  1987. X *
  1988. X * Revision 1.3  1992/06/18  21:21:44  spencer
  1989. X * Had forgotten to close the socket.
  1990. X *
  1991. X * Revision 1.2  1992/06/15  19:31:05  aggarwal
  1992. X * Made the include file stuff more portable.
  1993. X *
  1994. X * Revision 1.1  1992/06/12  21:02:49  aggarwal
  1995. X * Initial revision
  1996. X *
  1997. X */
  1998. X
  1999. X/*  Copyright 1992 JvNCnet */
  2000. X
  2001. X#include <sys/param.h>
  2002. X#include <sys/socket.h>
  2003. X#include <sys/errno.h>
  2004. X#include <time.h>
  2005. X#include <sys/time.h>
  2006. X
  2007. X#include <netinet/in.h>
  2008. X
  2009. X#include <stdio.h>
  2010. X#include <netdb.h>
  2011. X#ifndef NeXT
  2012. X#  include <unistd.h>
  2013. X#endif    /* NeXT */
  2014. X#include <signal.h>
  2015. X#include <fcntl.h>
  2016. X#include <setjmp.h>
  2017. X
  2018. Xextern char *prognm;
  2019. Xextern int errno;
  2020. X
  2021. X/*
  2022. X * setup_sockaddr -- given address (e.g. phoenix.princeton.edu) or an
  2023. X *    IP # (e.g. 128.112.120.1), fills in the struct sockaddr_in
  2024. X *    passed to it, with the port number requested
  2025. X *
  2026. X * returns 0 on success, -1 on error
  2027. X */
  2028. Xint
  2029. Xsetup_sockaddr(addr, to, port)
  2030. X  char *addr;
  2031. X  struct sockaddr_in *to;
  2032. X  short int port;
  2033. X{
  2034. X  struct hostent *hp;
  2035. X  int rtn = 0;
  2036. X
  2037. X  bzero((char *)to, sizeof(struct sockaddr_in));
  2038. X  to->sin_family = AF_INET;
  2039. X  to->sin_port = htons(port);
  2040. X  if (isdigit (*addr))
  2041. X  {
  2042. X      to->sin_addr.s_addr = inet_addr(addr);
  2043. X      if (to->sin_addr.s_addr == -1)
  2044. X    rtn = -1 ;
  2045. X  }
  2046. X  else
  2047. X  {
  2048. X      struct hostent *hp ;
  2049. X      if ((hp = gethostbyname(addr)) == NULL)
  2050. X      {
  2051. X      fprintf(stderr, "%s: unknown host: %s\n", prognm, addr);
  2052. X      rtn = -1;
  2053. X      }
  2054. X      else
  2055. X#ifdef h_addr    /* in netdb.h */
  2056. X    bcopy((char *)hp->h_addr, (char *)&to->sin_addr, hp->h_length);
  2057. X#else
  2058. X    bcopy((char *)hp->h_addr_list[0], (char *)&to->sin_addr, hp->h_length);
  2059. X#endif
  2060. X  }
  2061. X  return rtn;
  2062. X}
  2063. X
  2064. X/*
  2065. X * make_buffer -- creates a buffer of size nbytes and fills it with
  2066. X *     the pattern passed to it, or random chars if pattern is NULL
  2067. X */
  2068. Xchar *
  2069. Xmake_buffer(nbytes, pattern)
  2070. X  int nbytes;
  2071. X  char *pattern;
  2072. X{
  2073. X  char *buf;
  2074. X  int plen;
  2075. X  int i;
  2076. X
  2077. X  if ((buf = (char *)malloc(nbytes+1)) != NULL) {
  2078. X    if (pattern == NULL) {
  2079. X      plen = 0;
  2080. X      srand(getpid() ^ time((time_t *)0));
  2081. X    } else
  2082. X      plen = strlen(pattern);
  2083. X    for (i = 0; i < nbytes; i++) {
  2084. X      if (pattern == NULL)
  2085. X        buf[i] = rand() % 256;
  2086. X      else
  2087. X        buf[i] = pattern[i % plen];
  2088. X    }
  2089. X  }
  2090. X  return buf;
  2091. X}
  2092. X
  2093. Xjmp_buf env;    /* for SIGALRM handling */
  2094. X
  2095. X
  2096. X/*
  2097. X * throughput -- parameters and usage are described in tp.h and tpmon.h
  2098. X */
  2099. Xdouble
  2100. Xthroughput(addr, port, numbytes, blocksize, pattern, time, verbose)
  2101. X  char *addr, *pattern;
  2102. X  long numbytes;
  2103. X  int blocksize, time, verbose;
  2104. X  short int port;
  2105. X{
  2106. X  int i, s;             /* socket fd */
  2107. X  struct sockaddr_in sockad;    /* our destination */
  2108. X  struct hostent *hp;
  2109. X  char *buf,            /* data buffer */
  2110. X    error[81];            /* 81 sounded like a nice round number */
  2111. X  int written,            /* actual # bytes written by write() */
  2112. X    bytessent,             /* bytes sent successfully */
  2113. X    badwrites;            /* write() returned something != blocksize */
  2114. X  struct timeval tbeg, tend;    /* for timing purposes */
  2115. X  double bits, secs, tp;    /* for calculating times */
  2116. X  void stoptesting();
  2117. X
  2118. X
  2119. X  if (verbose) {
  2120. X    if (time) 
  2121. X      printf("%s: (throughput) sending for %d seconds\n", prognm, time);
  2122. X    else
  2123. X      printf("%s: (throughput) sending %.1fk bytes\n", prognm,
  2124. X        (float)numbytes/1024.0);
  2125. X  }
  2126. X  /* this lets us put the program name in perror() messages */
  2127. X  sprintf(error, "%s: ", prognm);
  2128. X
  2129. X  /* first fill up the buffer... */
  2130. X  if ((buf = make_buffer(blocksize, pattern)) == NULL) {
  2131. X    fprintf(stderr, "%s: out of memory in make_buffer\n", prognm);
  2132. X    return (double)-1.0;
  2133. X  }
  2134. X
  2135. X  /* now set things up for the writing */
  2136. X  bytessent = badwrites = 0;
  2137. X  if ((s = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
  2138. X    strcat(error, "socket");
  2139. X    perror(error);
  2140. X    return (double)-1.0;
  2141. X  }
  2142. X  if (setup_sockaddr(addr, &sockad, port) < 0)
  2143. X  {
  2144. X    close(s);
  2145. X    return (double)-1.0;
  2146. X  }
  2147. X  if (verbose) {
  2148. X    /* find out remote site's full name for printing out later */
  2149. X    hp = gethostbyaddr((char *)&sockad.sin_addr, sizeof(sockad.sin_addr),
  2150. X      AF_INET);
  2151. X    if (hp == NULL) {
  2152. X      strcat(error, "gethostbyaddr");
  2153. X      perror(error);
  2154. X      close (s);
  2155. X      return (double)-1.0;
  2156. X    }
  2157. X    addr = hp->h_name;
  2158. X    printf("Connecting to %s [%s], port %d...\n", inet_ntoa(&sockad.sin_addr),
  2159. X      addr, ntohs(sockad.sin_port));
  2160. X  }    
  2161. X  if (connect(s, (struct sockaddr *)&sockad, sizeof(sockad)) < 0) {
  2162. X    strcat(error, "connect to ");
  2163. X    strcat(error, inet_ntoa(&sockad.sin_addr));
  2164. X    perror(error);
  2165. X    close(s);
  2166. X    return (double)-1.0;
  2167. X  }
  2168. X#ifdef BSD
  2169. X  if (fcntl(s, F_SETFL, fcntl(s, F_GETFL, 0) | FNDELAY) < 0) {
  2170. X#else    /* SYS5 systems */
  2171. X  if (fcntl(s, F_SETFL, fcntl(s, F_GETFL, 0) | O_NDELAY) < 0) {
  2172. X#endif
  2173. X      strcat(error, "fcntl");
  2174. X      perror(error);
  2175. X      close(s);
  2176. X      return (double)-1.0;
  2177. X  }
  2178. X
  2179. X  /* if timing, set up the SIGALRM and set keepgoing to 1 for the loop */
  2180. X  signal(SIGINT, stoptesting);
  2181. X  if (time) {
  2182. X      signal(SIGALRM, stoptesting);
  2183. X      alarm(time);
  2184. X  }
  2185. X    
  2186. X  /* on your marks... get set... */
  2187. X  if (!setjmp(env)) {
  2188. X    gettimeofday(&tbeg, (struct timezone *)NULL);
  2189. X    do {
  2190. X      if ((written = write(s, buf, blocksize)) < 0) {
  2191. X        if ((errno == EWOULDBLOCK) || (errno == EINTR))
  2192. X          continue;
  2193. X        else
  2194. X          ++badwrites;
  2195. X      } else
  2196. X        bytessent += written;
  2197. X    } while (time || (bytessent < numbytes));
  2198. X  }
  2199. X
  2200. X  /*
  2201. X   * now ignore SIGALRM, just in case both time and numblocks were
  2202. X   * nonzero and we wrote out 'numbytes' bytes before 'time' seconds
  2203. X   * expired.  Also alarm(0) to cancel any pending alarms.
  2204. X   */
  2205. X  alarm(0);
  2206. X  signal(SIGALRM, SIG_IGN);
  2207. X  signal(SIGINT, SIG_DFL);
  2208. X
  2209. X  /* ok, we're done, how long did it really take? */
  2210. X  gettimeofday(&tend, (struct timezone *)NULL);
  2211. X  bits = (double)bytessent * (double)8.0;
  2212. X  secs = (double)(tend.tv_sec - tbeg.tv_sec) +
  2213. X         (double)(tend.tv_usec - tbeg.tv_usec) / (double)1000000.0;
  2214. X  tp = bits / secs;
  2215. X
  2216. X  if (verbose) 
  2217. X    printf("Successfully sent %.1fk in %4.3g seconds (%d bad writes)\n",
  2218. X      (float)(bytessent) / 1024.0, secs, badwrites);
  2219. X  if ((close(s) < 0) && verbose) {
  2220. X    strcat(error, "couldn't close socket [");
  2221. X    strcat(error, inet_ntoa(&sockad.sin_addr));
  2222. X    strcat(error, "] (non-fatal)");
  2223. X    perror(error);
  2224. X  }
  2225. X  return tp;
  2226. X}
  2227. X
  2228. X/*
  2229. X * stoptesting -- hack to break out of while loop in throughput()
  2230. X *     activated by SIGALRM
  2231. X */
  2232. Xvoid stoptesting()
  2233. X{
  2234. X  signal(SIGALRM, SIG_IGN);
  2235. X  signal(SIGINT, SIG_DFL);
  2236. X  longjmp(env, 1);
  2237. X}
  2238. END_OF_FILE
  2239.   if test 6824 -ne `wc -c <'nocol-3.0/src/tpmon/tpmon.c'`; then
  2240.     echo shar: \"'nocol-3.0/src/tpmon/tpmon.c'\" unpacked with wrong size!
  2241.   fi
  2242.   # end of 'nocol-3.0/src/tpmon/tpmon.c'
  2243. fi
  2244. if test -f 'nocol-3.0/src/trapmon/Makefile' -a "${1}" != "-c" ; then 
  2245.   echo shar: Will not clobber existing file \"'nocol-3.0/src/trapmon/Makefile'\"
  2246. else
  2247.   echo shar: Extracting \"'nocol-3.0/src/trapmon/Makefile'\" \(1883 characters\)
  2248.   sed "s/^X//" >'nocol-3.0/src/trapmon/Makefile' <<'END_OF_FILE'
  2249. X# $Id: Makefile,v 1.6 1993/10/30 03:30:28 aggarwal Exp $
  2250. X#
  2251. X# Makefile for 'trapmon'
  2252. X#
  2253. X
  2254. X## SET THIS
  2255. X# Directories needed by the Makefile. See description in ../Makefile
  2256. X#
  2257. XTOP =         /usr/nocol
  2258. XSRCDIR =    $(TOP)/src
  2259. XBINDIR =     $(TOP)/bin
  2260. X
  2261. X# directory for CMU snmp sources
  2262. XCMUSNMP =    $(SRCDIR)/cmu-snmp
  2263. XINCLUDEDIR =     $(SRCDIR)/include
  2264. XLIBDIR =    $(SRCDIR)/lib
  2265. X
  2266. X## SET THIS
  2267. X# Directories needed by the program.
  2268. X#    DATADIR            for creating the NSMON-OUTPUT
  2269. XDATADIR =     $(TOP)/data
  2270. X
  2271. X## SET THIS
  2272. X# Set the various defines for compile time defines:
  2273. X#
  2274. X#
  2275. XSYSDEFS =
  2276. XINSTALL =    install
  2277. X
  2278. X####
  2279. X#### Can leave the rest alone #######
  2280. X####
  2281. X
  2282. X##
  2283. X# The various directories that are needed in the program. Should NOT
  2284. X# have trailing '/'.
  2285. XDIRDEFS =    -DDATADIR=\"$(DATADIR)\"
  2286. X
  2287. X## Compilation definitions
  2288. X#  The CDEF specs are specific to this sub-module. The CFLAGS can be
  2289. X#  over-ridden by the top level makefile.
  2290. XCC =        cc
  2291. XCDEFS =        $(DIRDEFS) $(SYSDEFS) -DHAVE_FD_MACROS  \
  2292. X        -I$(CMUSNMP)/include
  2293. XLIBS =        -L$(CMUSNMP)/lib -lsnmp -lnocol $(SYSLIBS)
  2294. XCFLAGS =     -g -I$(INCLUDEDIR) -L$(LIBDIR)
  2295. X
  2296. XTARG  =        trapmon
  2297. XOBJECTS =     trapmon.o
  2298. X
  2299. X
  2300. X$(TARG): CMU $(OBJECTS) Makefile
  2301. X    $(CC) $(CFLAGS) $(OBJECTS) $(LIBS) -o $@
  2302. X
  2303. XCMU:
  2304. X    @echo 'Making the CMU SNMP library under $(CMUSNMP)'
  2305. X    cd $(CMUSNMP)/snmplib ; make RANLIB="$(RANLIB)" all install
  2306. X
  2307. X.c.o:
  2308. X    $(CC) -c $(CFLAGS) $(CDEFS) $<
  2309. X
  2310. X## The dependencies in case 'mkdep' not used
  2311. X#
  2312. X$(OBJECTS): $(INCLUDEDIR)/nocol.h  $(INCLUDEDIR)/trapmon.h
  2313. X
  2314. Xinstall: $(TARG)
  2315. X    $(INSTALL) -c -m 4750 $(TARG) $(BINDIR)/
  2316. X    @if [ `whoami` = "root" ]; then \
  2317. X        chown root $(BINDIR)/$(TARG) ;\
  2318. X        ls -lg $(BINDIR)/$(TARG) ;\
  2319. X     else \
  2320. X        echo "___Installed $(TARG) needs to be root suid___" ;\
  2321. X        echo "Do as root manually" ;\
  2322. X     fi
  2323. X
  2324. Xclean:
  2325. X    /bin/rm -f $(TARG) $(OBJECTS) core a.out
  2326. X    @-cd $(CMUSNMP) ; make clean
  2327. X
  2328. Xrcs:
  2329. X    @echo "Doing 'rcs' in 'nsmon'
  2330. X    @-for i in $(OBJS); do \
  2331. X        $(CO) -q `basename $$i .o`.c ;\
  2332. X      done
  2333. END_OF_FILE
  2334.   if test 1883 -ne `wc -c <'nocol-3.0/src/trapmon/Makefile'`; then
  2335.     echo shar: \"'nocol-3.0/src/trapmon/Makefile'\" unpacked with wrong size!
  2336.   fi
  2337.   # end of 'nocol-3.0/src/trapmon/Makefile'
  2338. fi
  2339. echo shar: End of archive 20 \(of 26\).
  2340. cp /dev/null ark20isdone
  2341. MISSING=""
  2342. 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
  2343.     if test ! -f ark${I}isdone ; then
  2344.     MISSING="${MISSING} ${I}"
  2345.     fi
  2346. done
  2347. if test "${MISSING}" = "" ; then
  2348.     echo You have unpacked all 26 archives.
  2349.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2350. else
  2351.     echo You still must unpack the following archives:
  2352.     echo "        " ${MISSING}
  2353. fi
  2354. exit 0
  2355. exit 0 # Just in case...
  2356.