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

  1. Newsgroups: comp.sources.misc
  2. From: vikas@jvnc.net (Vikas Aggarwal)
  3. Subject: v40i153:  nocol - Network Monitoring System, Part23/26
  4. Message-ID: <1993Nov24.163854.1993@sparky.sterling.com>
  5. X-Md4-Signature: 4c645ee2b5fcb78588c3a1b628328e80
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Wed, 24 Nov 1993 16:38:54 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: vikas@jvnc.net (Vikas Aggarwal)
  12. Posting-number: Volume 40, Issue 153
  13. Archive-name: nocol/part23
  14. Environment: INET, UNIX
  15.  
  16. #! /bin/sh
  17. # This is a shell archive.  Remove anything before this line, then feed it
  18. # into a shell via "sh file" or similar.  To overwrite existing files,
  19. # type "sh file -c".
  20. # Contents:  nocol-3.0/src/cmu-snmp/README
  21. #   nocol-3.0/src/cmu-snmp/apps/snmpd.c
  22. #   nocol-3.0/src/cmu-snmp/apps/snmpget.c
  23. #   nocol-3.0/src/cmu-snmp/apps/snmpgetnext.c
  24. #   nocol-3.0/src/cmu-snmp/man/snmpstatus.1
  25. #   nocol-3.0/src/cmu-snmp/man/snmptest.1
  26. #   nocol-3.0/src/cmu-snmp/man/snmptrap.1
  27. #   nocol-3.0/src/doc/perlnocol.3 nocol-3.0/src/doc/trapmon.8
  28. #   nocol-3.0/src/include/nocol.h nocol-3.0/src/include/trapmon.h
  29. #   nocol-3.0/src/lib/standalone.c nocol-3.0/src/netmon/fill_window.c
  30. #   nocol-3.0/src/netmon/parse_input.c
  31. #   nocol-3.0/src/netmon/read_filter.c nocol-3.0/src/perlnocol/bgpmon
  32. #   nocol-3.0/src/tpmon/tptest.c
  33. # Wrapped by kent@sparky on Tue Nov  9 22:22:26 1993
  34. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  35. echo If this archive is complete, you will see the following message:
  36. echo '          "shar: End of archive 23 (of 26)."'
  37. if test -f 'nocol-3.0/src/cmu-snmp/README' -a "${1}" != "-c" ; then 
  38.   echo shar: Will not clobber existing file \"'nocol-3.0/src/cmu-snmp/README'\"
  39. else
  40.   echo shar: Extracting \"'nocol-3.0/src/cmu-snmp/README'\" \(4489 characters\)
  41.   sed "s/^X//" >'nocol-3.0/src/cmu-snmp/README' <<'END_OF_FILE'
  42. X
  43. X  The files in this directory compromise the 1.0 release of the CMU SNMP
  44. Xdistribution.  This includes the SNMP/ASN.1 library, many client
  45. Xapplications, and supporting documentation.  The snmp agent for the Kinetics
  46. Xbox is included in this distribution, but the KIP code it links against is not
  47. Xyet distributable (this is not the released KIP code).  This will probably
  48. Xbe distributed at another time if there is sufficient demand.
  49. X
  50. XThis code was written with efficiency and portability in mind.  The
  51. Xapplications compile and run on the following systems: IBM PC/RT running ACIS
  52. XRelease 3, Sun3/60 running SUNOS 3.5, DEC microVax running Ultrix 2.2, and
  53. XDECStation 3100's runing Ultrix 3.0.  They are expected to run on any system
  54. Xwith a Berkeley socket interface.
  55. X
  56. XThe agent compiles into about 10 KB of 68000 code.  The machine independent
  57. Xportions of this agent also run on CMU's IBM PC/AT based router.
  58. X
  59. XThe applications are designed to be useful in the real world.  Snmpnetstat
  60. Xis a port of the Berkeley Unix netstat that gathers it's information using
  61. XSNMP.  (Many people will enjoy "snmpnetstat mygateway public -r").  Snmpstatus
  62. Xcollects several pieces of information and presents them in a useful format
  63. Xand is good for everyday status monitoring.  The rest of the tools are simpler,
  64. Xbut still interpret input and output symbolicly (they can be used without
  65. Xreferencing the RFC's!).
  66. X
  67. XFor instance, 
  68. Xsnmpnetstat mygateway public -r returns:
  69. XRouting tables
  70. XDestination      Gateway            Flags   Interface
  71. Xbbn-net-temp     psc-gw3.psc.edu    UG      Ethernet0
  72. Xarpanet          prpnet-gw.cc.cmu.e UG      Ethernet0
  73. Xxerox-net        psc-gw3.psc.edu    UG      Ethernet0
  74. Xhp-internet      psc-gw3.psc.edu    UG      Ethernet0
  75. X...
  76. X
  77. Xsnmpstatus returns:
  78. X[128.2.56.220]=>[Kinetics Fastpath2] Up: 1 day, 4:43:31
  79. XRecv/Trans packets - Interface: 262874/39867 | IP 47432/34587
  80. X
  81. XThe rest of the applications typically present a variable in a form similar
  82. Xto the following:
  83. XName: interfaces.ifTable.ifEntry.ifType.1
  84. XINTEGER: ethernet-csmacd(6)
  85. X
  86. XThe parsing and printing of symbolic object identifiers and the printing of
  87. Xtyped variables is driven by a database that describes the MIB.
  88. XThe MIB database is now retrieved from a text file in the ASN.1 format used in
  89. Xthe RFC1066 MIB.  This makes adding new (enterprise specific) mibs to the database
  90. Xvery simple.  I will solicit description files from other SNMP vendors and redistribute
  91. Xthem via anonymous FTP.  Initially, the mib.txt file contains a discription of the
  92. XRFC 1066 MIB and portions of the CMU enterprise specific MIB.  I had help in optimizing
  93. Xthe parser from Phil Lapsley of Berkeley (Thanks Phil!).
  94. X
  95. XFor further information, please consult the man pages.  There are man pages for
  96. Xeach of the applications, as well as for the Application Programming Interface (API).
  97. X
  98. XThe API has been redesigned to present a very convenient and useful asynchronous
  99. Xinterface to the SNMP transport.  In addition, snmp_client.c contains a toolkit
  100. Xof routines that simplify writing client applications.  In particular, there is
  101. Xa synchronous interface built on top of the asyncronous interface that makes
  102. Xwriting applications very easy.
  103. X
  104. XThis distribution is coprighted by CMU, but may be used and sold without
  105. Xpermission.  The snmpnetstat application is derived from the Berkeley 4.3 netstat,
  106. Xand is therefore also copyrighted by Berkeley.  Consult the copyright notices for
  107. Xfurther information.
  108. X
  109. XThe distribution is available by anonymous FTP from the host
  110. Xlancaster.andrew.cmu.edu (128.2.13.21) as the file pub/cmu-snmp1.0.tar.  I will
  111. Xmaintain a repository of mib description files in the directory pub/mibs.
  112. X
  113. XPlease direct questions, comments, and bug reports to sw0l+snmp@andrew.cmu.edu.
  114. XI have received very helpful feedback in the past that has been integrated into 
  115. Xthe current release.  This wil continue in the future.
  116. X
  117. XIf you pick up this package, please send me a note to the above address, so
  118. Xthat I may notify you of future enhancements/changes and additions to the
  119. Xset of applications (several are planned).  I will also redistribute applications
  120. Xusing the CMU SNMP library that were written elsewhere and placed in the public domain.
  121. XThere are already several such applications pending such a distribution.
  122. X
  123. XThere is a gateway at CMU running the agent.  Feel free to query it.  You
  124. Xcan access as netdev-kbox.cc.cmu.edu (128.2.56.220) with community name
  125. X"public".
  126. X
  127. X
  128. XSteve Waldbusser
  129. XNetwork Development
  130. XCarnegie-Mellon University
  131. END_OF_FILE
  132.   if test 4489 -ne `wc -c <'nocol-3.0/src/cmu-snmp/README'`; then
  133.     echo shar: \"'nocol-3.0/src/cmu-snmp/README'\" unpacked with wrong size!
  134.   fi
  135.   # end of 'nocol-3.0/src/cmu-snmp/README'
  136. fi
  137. if test -f 'nocol-3.0/src/cmu-snmp/apps/snmpd.c' -a "${1}" != "-c" ; then 
  138.   echo shar: Will not clobber existing file \"'nocol-3.0/src/cmu-snmp/apps/snmpd.c'\"
  139. else
  140.   echo shar: Extracting \"'nocol-3.0/src/cmu-snmp/apps/snmpd.c'\" \(3738 characters\)
  141.   sed "s/^X//" >'nocol-3.0/src/cmu-snmp/apps/snmpd.c' <<'END_OF_FILE'
  142. X/*
  143. X * snmpd.c - send snmp GET requests to a network entity.
  144. X *
  145. X */
  146. X/***********************************************************
  147. X    Copyright 1988, 1989 by Carnegie Mellon University
  148. X
  149. X                      All Rights Reserved
  150. X
  151. XPermission to use, copy, modify, and distribute this software and its 
  152. Xdocumentation for any purpose and without fee is hereby granted, 
  153. Xprovided that the above copyright notice appear in all copies and that
  154. Xboth that copyright notice and this permission notice appear in 
  155. Xsupporting documentation, and that the name of CMU not be
  156. Xused in advertising or publicity pertaining to distribution of the
  157. Xsoftware without specific, written prior permission.  
  158. X
  159. XCMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  160. XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  161. XCMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  162. XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  163. XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  164. XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  165. XSOFTWARE.
  166. X******************************************************************/
  167. X#include <sys/types.h>
  168. X#include <netinet/in.h>
  169. X#include <stdio.h>
  170. X#include <sys/socket.h>
  171. X#include <errno.h>
  172. X
  173. X#include "snmp.h"
  174. X#include "snmp_impl.h"
  175. X#include "asn1.h"
  176. X
  177. Xextern int  errno;
  178. Xint    snmp_dump_packet = 0;
  179. X
  180. Xmain(argc, argv)
  181. X    int        argc;
  182. X    char    *argv[];
  183. X{
  184. X    int    arg;
  185. X    int sd;
  186. X    struct sockaddr_in    me;
  187. X
  188. X
  189. X    /*
  190. X     * usage: snmpd
  191. X     */
  192. X    for(arg = 1; arg < argc; arg++){
  193. X    if (argv[arg][0] == '-'){
  194. X        switch(argv[arg][1]){
  195. X        case 'd':
  196. X            snmp_dump_packet++;
  197. X            break;
  198. X        default:
  199. X            printf("invalid option: -%c\n", argv[arg][1]);
  200. X            break;
  201. X        }
  202. X        continue;
  203. X    }
  204. X    }
  205. X    /* Set up connections */
  206. X    sd = socket(AF_INET, SOCK_DGRAM, 0);
  207. X    if (sd < 0){
  208. X    perror("socket");
  209. X    return 0;
  210. X    }
  211. X    me.sin_family = AF_INET;
  212. X    me.sin_addr.s_addr = INADDR_ANY;
  213. X    me.sin_port = htons(SNMP_PORT);
  214. X    if (bind(sd, (struct sockaddr *)&me, sizeof(me)) != 0){
  215. X    perror("bind");
  216. X    return 0;
  217. X    }
  218. X    init_snmp();
  219. X    receive(sd);
  220. X}
  221. X
  222. Xreceive(sd)
  223. X    int sd;
  224. X{
  225. X    int numfds;
  226. X    fd_set fdset;
  227. X    int count;
  228. X
  229. X    while(1){
  230. X    numfds = 0;
  231. X    FD_ZERO(&fdset);
  232. X    numfds = sd + 1;
  233. X    FD_SET(sd, &fdset);
  234. X    count = select(numfds, &fdset, 0, 0, 0);
  235. X    if (count > 0){
  236. X        if(FD_ISSET(sd, &fdset))
  237. X        snmp_read(sd);
  238. X    } else switch(count){
  239. X        case 0:
  240. X        break;
  241. X        case -1:
  242. X        if (errno == EINTR){
  243. X            continue;
  244. X        } else {
  245. X            perror("select");
  246. X        }
  247. X        return -1;
  248. X        default:
  249. X        printf("select returned %d\n", count);
  250. X        return -1;
  251. X    }
  252. X    }
  253. X}
  254. X
  255. Xsnmp_read(sd)
  256. X    int sd;
  257. X{
  258. X    struct sockaddr_in    from;
  259. X    int length, out_length, fromlength;
  260. X    u_char  packet[1500], outpacket[1500];
  261. X
  262. X    fromlength = sizeof from;
  263. X    length = recvfrom(sd, packet, 1500, 0, (struct sockaddr *)&from, &fromlength);
  264. X    if (length == -1)
  265. X    perror("recvfrom");
  266. X    if (snmp_dump_packet){
  267. X    int count;
  268. X
  269. X    printf("recieved %d bytes from %s:\n", length, inet_ntoa(from.sin_addr));
  270. X    for(count = 0; count < length; count++){
  271. X        printf("%02X ", packet[count]);
  272. X        if ((count % 16) == 15)
  273. X        printf("\n");
  274. X    }
  275. X    printf("\n\n");
  276. X    }
  277. X    out_length = 1500;
  278. X    if (snmp_agent_parse(packet, length, outpacket, &out_length, from.sin_addr)){
  279. X    if (snmp_dump_packet){
  280. X        int count;
  281. X
  282. X        printf("sent %d bytes to %s:\n", out_length, inet_ntoa(from.sin_addr));
  283. X        for(count = 0; count < out_length; count++){
  284. X        printf("%02X ", outpacket[count]);
  285. X        if ((count % 16) == 15)
  286. X            printf("\n");
  287. X        }
  288. X        printf("\n\n");
  289. X    }
  290. X    if (sendto(sd, (char *)outpacket, out_length, 0, (struct sockaddr *)&from,
  291. X        sizeof(from)) < 0){
  292. X        perror("sendto");
  293. X        return 0;
  294. X    }
  295. X
  296. X    }
  297. X    
  298. X}
  299. X
  300. END_OF_FILE
  301.   if test 3738 -ne `wc -c <'nocol-3.0/src/cmu-snmp/apps/snmpd.c'`; then
  302.     echo shar: \"'nocol-3.0/src/cmu-snmp/apps/snmpd.c'\" unpacked with wrong size!
  303.   fi
  304.   # end of 'nocol-3.0/src/cmu-snmp/apps/snmpd.c'
  305. fi
  306. if test -f 'nocol-3.0/src/cmu-snmp/apps/snmpget.c' -a "${1}" != "-c" ; then 
  307.   echo shar: Will not clobber existing file \"'nocol-3.0/src/cmu-snmp/apps/snmpget.c'\"
  308. else
  309.   echo shar: Extracting \"'nocol-3.0/src/cmu-snmp/apps/snmpget.c'\" \(4136 characters\)
  310.   sed "s/^X//" >'nocol-3.0/src/cmu-snmp/apps/snmpget.c' <<'END_OF_FILE'
  311. X/*
  312. X * snmpget.c - send snmp GET requests to a network entity.
  313. X *
  314. X */
  315. X/***********************************************************
  316. X    Copyright 1988, 1989 by Carnegie Mellon University
  317. X
  318. X                      All Rights Reserved
  319. X
  320. XPermission to use, copy, modify, and distribute this software and its 
  321. Xdocumentation for any purpose and without fee is hereby granted, 
  322. Xprovided that the above copyright notice appear in all copies and that
  323. Xboth that copyright notice and this permission notice appear in 
  324. Xsupporting documentation, and that the name of CMU not be
  325. Xused in advertising or publicity pertaining to distribution of the
  326. Xsoftware without specific, written prior permission.  
  327. X
  328. XCMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  329. XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  330. XCMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  331. XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  332. XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  333. XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  334. XSOFTWARE.
  335. X******************************************************************/
  336. X#include <sys/types.h>
  337. X#include <netinet/in.h>
  338. X#include <stdio.h>
  339. X
  340. X#include "snmp.h"
  341. X#include "snmp_impl.h"
  342. X#include "asn1.h"
  343. X#include "snmp_api.h"
  344. X#include "snmp_client.h"
  345. X
  346. Xextern int  errno;
  347. Xint    snmp_dump_packet = 0;
  348. X
  349. Xmain(argc, argv)
  350. X    int        argc;
  351. X    char    *argv[];
  352. X{
  353. X    struct snmp_session session, *ss;
  354. X    struct snmp_pdu *pdu, *response;
  355. X    struct variable_list *vars;
  356. X    int    arg;
  357. X    char *gateway = NULL;
  358. X    char *community = NULL;
  359. X    int    count, current_name = 0;
  360. X    char *names[128];
  361. X    oid name[MAX_NAME_LEN];
  362. X    int name_length;
  363. X    int status;
  364. X
  365. X    init_mib();
  366. X    /*
  367. X     * usage: snmpget gateway-name community-name
  368. X     */
  369. X    for(arg = 1; arg < argc; arg++){
  370. X    if (argv[arg][0] == '-'){
  371. X        switch(argv[arg][1]){
  372. X        case 'd':
  373. X            snmp_dump_packet++;
  374. X            break;
  375. X        default:
  376. X            printf("invalid option: -%c\n", argv[arg][1]);
  377. X            break;
  378. X        }
  379. X        continue;
  380. X    }
  381. X    if (gateway == NULL){
  382. X        gateway = argv[arg];
  383. X    } else if (community == NULL){
  384. X        community = argv[arg]; 
  385. X    } else {
  386. X        names[current_name++] = argv[arg];
  387. X    }
  388. X    }
  389. X
  390. X    if (!(gateway && community && current_name > 0)){
  391. X    printf("usage: snmpget gateway-name community-name object-identifier [object-identifier ...]\n");
  392. X    exit(1);
  393. X    }
  394. X
  395. X    bzero((char *)&session, sizeof(struct snmp_session));
  396. X    session.peername = gateway;
  397. X    session.community = (u_char *)community;
  398. X    session.community_len = strlen((char *)community);
  399. X    session.retries = SNMP_DEFAULT_RETRIES;
  400. X    session.timeout = SNMP_DEFAULT_TIMEOUT;
  401. X    session.authenticator = NULL;
  402. X    snmp_synch_setup(&session);
  403. X    ss = snmp_open(&session);
  404. X    if (ss == NULL){
  405. X    printf("Couldn't open snmp\n");
  406. X    exit(-1);
  407. X    }
  408. X
  409. X    pdu = snmp_pdu_create(GET_REQ_MSG);
  410. X
  411. X    for(count = 0; count < current_name; count++){
  412. X    name_length = MAX_NAME_LEN;
  413. X    if (!read_objid(names[count], name, &name_length)){
  414. X        printf("Invalid object identifier: %s\n", names[count]);
  415. X    }
  416. X    
  417. X    snmp_add_null_var(pdu, name, name_length);
  418. X    }
  419. X
  420. Xretry:
  421. X    status = snmp_synch_response(ss, pdu, &response);
  422. X    if (status == STAT_SUCCESS){
  423. X    if (response->errstat == SNMP_ERR_NOERROR){
  424. X        for(vars = response->variables; vars; vars = vars->next_variable)
  425. X        print_variable(vars->name, vars->name_length, vars);
  426. X    } else {
  427. X        printf("Error in packet.\nReason: %s\n", snmp_errstring(response->errstat));
  428. X        if (response->errstat == SNMP_ERR_NOSUCHNAME){
  429. X        printf("This name doesn't exist: ");
  430. X        for(count = 1, vars = response->variables; vars && count != response->errindex;
  431. X            vars = vars->next_variable, count++)
  432. X            ;
  433. X        if (vars)
  434. X            print_objid(vars->name, vars->name_length);
  435. X        printf("\n");
  436. X        }
  437. X        if ((pdu = snmp_fix_pdu(response, GET_REQ_MSG)) != NULL)
  438. X        goto retry;
  439. X    }
  440. X
  441. X    } else if (status == STAT_TIMEOUT){
  442. X    printf("No Response from %s\n", gateway);
  443. X    } else {    /* status == STAT_ERROR */
  444. X    printf("An error occurred, Quitting\n");
  445. X    }
  446. X
  447. X    if (response)
  448. X    snmp_free_pdu(response);
  449. X    snmp_close(ss);
  450. X}
  451. X
  452. END_OF_FILE
  453.   if test 4136 -ne `wc -c <'nocol-3.0/src/cmu-snmp/apps/snmpget.c'`; then
  454.     echo shar: \"'nocol-3.0/src/cmu-snmp/apps/snmpget.c'\" unpacked with wrong size!
  455.   fi
  456.   # end of 'nocol-3.0/src/cmu-snmp/apps/snmpget.c'
  457. fi
  458. if test -f 'nocol-3.0/src/cmu-snmp/apps/snmpgetnext.c' -a "${1}" != "-c" ; then 
  459.   echo shar: Will not clobber existing file \"'nocol-3.0/src/cmu-snmp/apps/snmpgetnext.c'\"
  460. else
  461.   echo shar: Extracting \"'nocol-3.0/src/cmu-snmp/apps/snmpgetnext.c'\" \(4218 characters\)
  462.   sed "s/^X//" >'nocol-3.0/src/cmu-snmp/apps/snmpgetnext.c' <<'END_OF_FILE'
  463. X/*
  464. X * snmpgetnext.c - send snmp GETNEXT requests to a network entity.
  465. X *
  466. X */
  467. X/***********************************************************
  468. X    Copyright 1988, 1989 by Carnegie Mellon University
  469. X
  470. X                      All Rights Reserved
  471. X
  472. XPermission to use, copy, modify, and distribute this software and its 
  473. Xdocumentation for any purpose and without fee is hereby granted, 
  474. Xprovided that the above copyright notice appear in all copies and that
  475. Xboth that copyright notice and this permission notice appear in 
  476. Xsupporting documentation, and that the name of CMU not be
  477. Xused in advertising or publicity pertaining to distribution of the
  478. Xsoftware without specific, written prior permission.  
  479. X
  480. XCMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  481. XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  482. XCMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  483. XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  484. XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  485. XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  486. XSOFTWARE.
  487. X******************************************************************/
  488. X#include <sys/types.h>
  489. X#include <netinet/in.h>
  490. X#include <stdio.h>
  491. X
  492. X#include "snmp.h"
  493. X#include "snmp_impl.h"
  494. X#include "asn1.h"
  495. X#include "snmp_api.h"
  496. X#include "snmp_client.h"
  497. X
  498. Xextern int  errno;
  499. Xint    snmp_dump_packet = 0;
  500. X
  501. Xmain(argc, argv)
  502. X    int        argc;
  503. X    char    *argv[];
  504. X{
  505. X    struct snmp_session session, *ss;
  506. X    struct snmp_pdu *pdu, *response;
  507. X    struct variable_list *vars;
  508. X    int    arg;
  509. X    char *gateway = NULL;
  510. X    char *community = NULL;
  511. X    int    count, current_name = 0;
  512. X    char *names[128];
  513. X    oid name[MAX_NAME_LEN];
  514. X    int name_length;
  515. X    int status;
  516. X
  517. X    init_mib();
  518. X    /*
  519. X     * usage: snmpgetnext gateway-name community-name object-id-list
  520. X     */
  521. X    for(arg = 1; arg < argc; arg++){
  522. X    if (argv[arg][0] == '-'){
  523. X        switch(argv[arg][1]){
  524. X        case 'd':
  525. X            snmp_dump_packet++;
  526. X            break;
  527. X        default:
  528. X            printf("invalid option: -%c\n", argv[arg][1]);
  529. X            break;
  530. X        }
  531. X        continue;
  532. X    }
  533. X    if (gateway == NULL){
  534. X        gateway = argv[arg];
  535. X    } else if (community == NULL){
  536. X        community = argv[arg]; 
  537. X    } else {
  538. X        names[current_name++] = argv[arg];
  539. X    }
  540. X    }
  541. X
  542. X    if (!(gateway && community && current_name > 0)){
  543. X    printf("usage: snmpgetnext gateway-name community-name object-identifier [object-identifier ...]\n");
  544. X    exit(1);
  545. X    }
  546. X
  547. X    bzero((char *)&session, sizeof(struct snmp_session));
  548. X    session.peername = gateway;
  549. X    session.community = (u_char *)community;
  550. X    session.community_len = strlen((char *)community);
  551. X    session.retries = SNMP_DEFAULT_RETRIES;
  552. X    session.timeout = SNMP_DEFAULT_TIMEOUT;
  553. X    session.authenticator = NULL;
  554. X    snmp_synch_setup(&session);
  555. X    ss = snmp_open(&session);
  556. X    if (ss == NULL){
  557. X    printf("Couldn't open snmp\n");
  558. X    exit(-1);
  559. X    }
  560. X
  561. X    pdu = snmp_pdu_create(GETNEXT_REQ_MSG);
  562. X
  563. X    for(count = 0; count < current_name; count++){
  564. X    name_length = MAX_NAME_LEN;
  565. X    if (!read_objid(names[count], name, &name_length)){
  566. X        printf("Invalid object identifier: %s\n", names[count]);
  567. X    }
  568. X    
  569. X    snmp_add_null_var(pdu, name, name_length);
  570. X    }
  571. X
  572. X    status = snmp_synch_response(ss, pdu, &response);
  573. X    if (status == STAT_SUCCESS){
  574. X    if (response->errstat == SNMP_ERR_NOERROR){
  575. X        for(vars = response->variables; vars; vars = vars->next_variable)
  576. X        print_variable(vars->name, vars->name_length, vars);
  577. X    } else {
  578. X        if (response->errstat == SNMP_ERR_NOSUCHNAME){
  579. X        printf("You have reached the end of the MIB.\n");
  580. X        } else {
  581. X        printf("Error in packet.\nReason: %s\n", snmp_errstring(response->errstat));
  582. X        if (response->errstat == SNMP_ERR_NOSUCHNAME){
  583. X            printf("This name doesn't exist: ");
  584. X            for(count = 1, vars = response->variables; vars && count != response->errindex;
  585. X            vars = vars->next_variable, count++)
  586. X                ;
  587. X            if (vars)
  588. X            print_objid(vars->name, vars->name_length);
  589. X            printf("\n");
  590. X        }
  591. X        }
  592. X    }
  593. X
  594. X    } else if (status == STAT_TIMEOUT){
  595. X    printf("No Response from %s\n", gateway);
  596. X    } else {    /* status == STAT_ERROR */
  597. X    printf("An error occurred, Quitting\n");
  598. X    }
  599. X
  600. X    if (response)
  601. X    snmp_free_pdu(response);
  602. X    snmp_close(ss);
  603. X}
  604. X
  605. END_OF_FILE
  606.   if test 4218 -ne `wc -c <'nocol-3.0/src/cmu-snmp/apps/snmpgetnext.c'`; then
  607.     echo shar: \"'nocol-3.0/src/cmu-snmp/apps/snmpgetnext.c'\" unpacked with wrong size!
  608.   fi
  609.   # end of 'nocol-3.0/src/cmu-snmp/apps/snmpgetnext.c'
  610. fi
  611. if test -f 'nocol-3.0/src/cmu-snmp/man/snmpstatus.1' -a "${1}" != "-c" ; then 
  612.   echo shar: Will not clobber existing file \"'nocol-3.0/src/cmu-snmp/man/snmpstatus.1'\"
  613. else
  614.   echo shar: Extracting \"'nocol-3.0/src/cmu-snmp/man/snmpstatus.1'\" \(3422 characters\)
  615.   sed "s/^X//" >'nocol-3.0/src/cmu-snmp/man/snmpstatus.1' <<'END_OF_FILE'
  616. X.\* /***********************************************************
  617. X.\"     Copyright 1988, 1989 by Carnegie Mellon University
  618. X.\" 
  619. X.\"                       All Rights Reserved
  620. X.\" 
  621. X.\" Permission to use, copy, modify, and distribute this software and its 
  622. X.\" documentation for any purpose and without fee is hereby granted, 
  623. X.\" provided that the above copyright notice appear in all copies and that
  624. X.\" both that copyright notice and this permission notice appear in 
  625. X.\" supporting documentation, and that the name of CMU not be
  626. X.\" used in advertising or publicity pertaining to distribution of the
  627. X.\" software without specific, written prior permission.  
  628. X.\" 
  629. X.\" CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  630. X.\" ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  631. X.\" CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  632. X.\" ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  633. X.\" WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  634. X.\" ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  635. X.\" SOFTWARE.
  636. X.\" ******************************************************************/
  637. X.TH SNMPSTATUS 1 "17 September 1989"
  638. X.UC 4
  639. X.SH NAME
  640. Xsnmpstatus - Retrieves important information from a network entity.
  641. X.SH SYNOPSIS
  642. Xsnmpstatus host [community]
  643. X.SH DESCRIPTION
  644. XSnmpstatus is an SNMP application that retrieves several important
  645. Xstatistics from a network entity.
  646. X.PP
  647. XThe
  648. X.I host
  649. Xspecification may be either a host name or an internet address
  650. Xspecified in "dot notation"
  651. X.PP
  652. XThe
  653. X.I community
  654. Xspecifies the community name for the transaction with the remote system.
  655. XIf this argument is not given, the community name will default to
  656. X.I "public".
  657. X.PP
  658. XThe information returned is:
  659. X.PP
  660. XThe IP address of the entity.
  661. X.br
  662. XA textual description of the entity
  663. X.I (sysDescr.0)
  664. X.br
  665. XThe uptime of the entity
  666. X.I (sysUpTime.0)
  667. X.br
  668. XThe sum of received packets on all interfaces
  669. X.I (ifInUCastPkts.* + ifInNUCastPkts.*)
  670. X.br
  671. XThe sum of transmitted packets on all interfaces
  672. X.I (ifOutUCastPkts.* + ifOutNUCastPkts.*)
  673. X.br
  674. XThe number of IP input packets
  675. X.I (ipInReceives.0)
  676. X.br
  677. XThe number of IP output packets
  678. X.I (ipOutRequests.0)
  679. X.PP
  680. XFor example
  681. X.PP
  682. X.I snmpstatus netdev-kbox.cc.cmu.edu public
  683. X.PP
  684. Xwill produce output similar to the following:
  685. X.PP
  686. X.I [128.2.56.220]=>[Kinetics FastPath2] Up: 1 day, 4:43:31
  687. X.br
  688. X.I IF recv/trans packets 262874/39867 |
  689. X.I IP recv/trans packets 31603/15805
  690. X.PP
  691. XSnmpstatus also checks the operational status of all interfaces (ifOperStatus.*),
  692. Xand if it finds any that are not running, it will report in a manner similar to this:
  693. X.PP
  694. X.I 2 interfaces are down!
  695. XThe
  696. X.I host
  697. Xspecification may be either a host name or an internet address
  698. Xspecified in "dot notation"
  699. X.PP
  700. XThe
  701. X.I community
  702. Xspecifies the community name for the transaction with the remote system.  If none is
  703. Xgiven, the community name defaults to
  704. X.I "public".
  705. X.PP
  706. XIf the network entity has an error processing the request packet, an error
  707. Xpacket will be returned and a message will be shown, helping to pinpoint in what way
  708. Xthe request was malformed.  Snmpstatus will attempt to reform it's request to eliminate
  709. Xthe malformed variable, but this variable will then be missing from the displayed data.
  710. X.PP
  711. XAdding a "-d" to the argument list will cause the application to dump input and output packets.
  712. X.PP
  713. X.SH "SEE ALSO"
  714. XRFC 1065, RFC 1066, RFC 1067
  715. END_OF_FILE
  716.   if test 3422 -ne `wc -c <'nocol-3.0/src/cmu-snmp/man/snmpstatus.1'`; then
  717.     echo shar: \"'nocol-3.0/src/cmu-snmp/man/snmpstatus.1'\" unpacked with wrong size!
  718.   fi
  719.   # end of 'nocol-3.0/src/cmu-snmp/man/snmpstatus.1'
  720. fi
  721. if test -f 'nocol-3.0/src/cmu-snmp/man/snmptest.1' -a "${1}" != "-c" ; then 
  722.   echo shar: Will not clobber existing file \"'nocol-3.0/src/cmu-snmp/man/snmptest.1'\"
  723. else
  724.   echo shar: Extracting \"'nocol-3.0/src/cmu-snmp/man/snmptest.1'\" \(3555 characters\)
  725.   sed "s/^X//" >'nocol-3.0/src/cmu-snmp/man/snmptest.1' <<'END_OF_FILE'
  726. X.\* /***********************************************************
  727. X.\"     Copyright 1988, 1989 by Carnegie Mellon University
  728. X.\" 
  729. X.\"                       All Rights Reserved
  730. X.\" 
  731. X.\" Permission to use, copy, modify, and distribute this software and its 
  732. X.\" documentation for any purpose and without fee is hereby granted, 
  733. X.\" provided that the above copyright notice appear in all copies and that
  734. X.\" both that copyright notice and this permission notice appear in 
  735. X.\" supporting documentation, and that the name of CMU not be
  736. X.\" used in advertising or publicity pertaining to distribution of the
  737. X.\" software without specific, written prior permission.  
  738. X.\" 
  739. X.\" CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  740. X.\" ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  741. X.\" CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  742. X.\" ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  743. X.\" WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  744. X.\" ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  745. X.\" SOFTWARE.
  746. X.\" ******************************************************************/
  747. X.TH SNMPTEST 1 "17 September 1989"
  748. X.UC 4
  749. X.SH NAME
  750. Xsnmptest - communicates with a network entity using SNMP GET Requests.
  751. X.SH SYNOPSIS
  752. Xsnmptest host community
  753. X.SH DESCRIPTION
  754. XSnmptest is a flexible SNMP application that can monitor and manage
  755. Xinformation on a network entity.
  756. X.PP
  757. XThe
  758. X.I host
  759. Xspecification may be either a host name or an internet address
  760. Xspecified in "dot notation"
  761. X.PP
  762. XThe
  763. X.I community
  764. Xspecifies the community name for the transaction with the remote system.
  765. X.PP
  766. XAfter invoking the program, a command line
  767. Xinterpreter proceeds to accept commands.  It will prompt with:
  768. X.PP
  769. X.I Please enter the variable name:
  770. X.PP
  771. XAt this point you can enter one or more variable names, one per line.
  772. XA blank line is a command to send a request for each of the variables (in a single
  773. Xpacket) to the remote entity. Each variable name is given in the format specified in
  774. X.IR variables (5).
  775. XFor example
  776. X.PP
  777. X.I snmpget netdev-kbox.cc.cmu.edu public
  778. X.br
  779. X.I Please enter the variable name: system.sysdescr.0
  780. X.br
  781. X.I Please enter the variable name: 
  782. X.PP
  783. XWill return some information about the request and reply packets, as well as the
  784. Xinformation:
  785. X.PP
  786. X.I Name: system.sysDescr.0
  787. X.br
  788. X.I OCTET STRING- (ascii):    Kinetics FastPath2
  789. X.PP
  790. XUpon startup, the program defaults to sending a GET Request packet.  This can be changed
  791. Xto a GET NEXT Request or a SET Request by typing the commands "$N" or "$S" repectively.  Typing
  792. X"$G" will go back to the GET Request mode.
  793. X.PP
  794. XThe command "$D" will toggle the dumping of each sent and received packet.
  795. X.PP
  796. XWhen in the "SET Request" mode, more information is requested by the prompt for each variable.  The prompt:
  797. X.PP
  798. X.I Please enter variable type [i|s|n]: 
  799. X.PP
  800. Xrequests the type of the variable be entered.  Type "i" for an integer, "s" for an octet string,
  801. Xand "n" for a null value.
  802. X.br
  803. XAt this point a value will be prompted for:
  804. X.PP
  805. X.I Please enter new value: 
  806. X.PP
  807. XIf this is an integer value, just type the integer (in decimal).  If it is a string, type in
  808. Xwhite-space seperated decimal numbers, one per byte of the string.  Again type a blank line at
  809. Xthe prompt for the variable name to send the packet.
  810. X.PP
  811. XAt the variable name line, typing "$Q" will quit the program.
  812. X.PP
  813. XAdding a "-d" to the argument list will cause the application to dump input and output packets.
  814. X.PP
  815. X.SH "SEE ALSO"
  816. Xvariables(5), RFC 1065, RFC 1066, RFC 1067
  817. END_OF_FILE
  818.   if test 3555 -ne `wc -c <'nocol-3.0/src/cmu-snmp/man/snmptest.1'`; then
  819.     echo shar: \"'nocol-3.0/src/cmu-snmp/man/snmptest.1'\" unpacked with wrong size!
  820.   fi
  821.   # end of 'nocol-3.0/src/cmu-snmp/man/snmptest.1'
  822. fi
  823. if test -f 'nocol-3.0/src/cmu-snmp/man/snmptrap.1' -a "${1}" != "-c" ; then 
  824.   echo shar: Will not clobber existing file \"'nocol-3.0/src/cmu-snmp/man/snmptrap.1'\"
  825. else
  826.   echo shar: Extracting \"'nocol-3.0/src/cmu-snmp/man/snmptrap.1'\" \(3877 characters\)
  827.   sed "s/^X//" >'nocol-3.0/src/cmu-snmp/man/snmptrap.1' <<'END_OF_FILE'
  828. X.\* /***********************************************************
  829. X.\"     Copyright 1988, 1989 by Carnegie Mellon University
  830. X.\" 
  831. X.\"                       All Rights Reserved
  832. X.\" 
  833. X.\" Permission to use, copy, modify, and distribute this software and its 
  834. X.\" documentation for any purpose and without fee is hereby granted, 
  835. X.\" provided that the above copyright notice appear in all copies and that
  836. X.\" both that copyright notice and this permission notice appear in 
  837. X.\" supporting documentation, and that the name of CMU not be
  838. X.\" used in advertising or publicity pertaining to distribution of the
  839. X.\" software without specific, written prior permission.  
  840. X.\" 
  841. X.\" CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  842. X.\" ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  843. X.\" CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  844. X.\" ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  845. X.\" WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  846. X.\" ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  847. X.\" SOFTWARE.
  848. X.\" ******************************************************************/
  849. X.TH SNMPTRAP 1 "17 September 1989"
  850. X.UC 4
  851. X.SH NAME
  852. Xsnmptrap - Send an SNMP TRAP message to a host.
  853. X.SH SYNOPSIS
  854. Xsnmptrap host community trap-type specific-type device-description [ -a agent-addr ]
  855. X.SH DESCRIPTION
  856. Xsnmptrap is an SNMP application that forms and sends an SNMP TRAP message to
  857. Xa host.
  858. X.PP
  859. XThe
  860. X.I host
  861. Xspecification may be either a host name or an internet address
  862. Xspecified in "dot notation"
  863. X.PP
  864. XThe
  865. X.I community
  866. Xspecifies the community name for the transaction with the remote system.
  867. X.PP
  868. XThe
  869. X.I trap-type
  870. Xand
  871. X.I specific-type
  872. Xare integers that specify the type of trap message being sent.
  873. X.PP
  874. XThe
  875. X.I device-description
  876. Xis a textual description of the device sending this trap, to be used as the value of
  877. Xa system.sysDescr.0 variable sent in the variable list of this trap message.
  878. XThe optional argument
  879. X.I -a agent-addr
  880. Xcan be used to change the address from which the trap reports it is being sent.  Otherwise
  881. Xthe sending host's address is used.
  882. X.PP
  883. XFor example
  884. X.PP
  885. X.I snmptrap nic.andrew.cmu.edu public 0 0
  886. X.I 'SUN 3/60: SUNOS4.0'
  887. X.PP
  888. Xwill send a Cold Start trap to the specified machine.
  889. X.PP
  890. XThe defined trap types are:
  891. X.TP
  892. X.B 0
  893. XcoldStart \- signifies that the sending protocol entity is
  894. Xreinitializing itself such that the agent's configuration or the
  895. Xprotocol entity implementation may be altered.
  896. X.TP
  897. X.B 1
  898. XwarmStart \- signifies that the sending protocol entity is
  899. Xreinitializing itself such that neither the agent configuration nor
  900. Xthe protocol entity implementation is altered.
  901. X.TP
  902. X.B 2
  903. XlinkDown \- signifies that the sending protocol entity
  904. Xrecognizes a failure in one of the communication links represented in
  905. Xthe agent's configuration.
  906. X.TP
  907. X.B 3
  908. XlinkUp \- signifies that the sending protocol entity
  909. Xrecognizes that one of the communication links represented in the
  910. Xagent's configuration has come up.
  911. X.TP
  912. X.B 4
  913. XauthenticationFailure \- signifies that the sending protocol
  914. Xentity is the addressee of a protocol message that is not properly
  915. Xauthenticated.  While implementations of the SNMP must be capable of
  916. Xgenerating this trap, they must also be capable of suppressing the
  917. Xemission of such traps via an implementation-specific mechanism.
  918. X.TP
  919. X.B 5
  920. XegpNeighborLoss \- signifies that an EGP neighbor for whom
  921. Xthe sending protocol entity was an EGP peer has been marked down and
  922. Xthe peer relationship no longer obtains.
  923. X.TP
  924. X.B 6
  925. XenterpriseSpecific \- signifies that the sending protocol
  926. Xentity recognizes that some enterprise-specific event has occurred.
  927. XThe specific-trap field identifies the particular trap which
  928. Xoccurred.
  929. X.PP
  930. XAdding a "-d" to the argument list will cause the application to dump the output packet.
  931. X.PP
  932. X.SH "SEE ALSO"
  933. XRFC 1065, RFC 1066, RFC 1067
  934. END_OF_FILE
  935.   if test 3877 -ne `wc -c <'nocol-3.0/src/cmu-snmp/man/snmptrap.1'`; then
  936.     echo shar: \"'nocol-3.0/src/cmu-snmp/man/snmptrap.1'\" unpacked with wrong size!
  937.   fi
  938.   # end of 'nocol-3.0/src/cmu-snmp/man/snmptrap.1'
  939. fi
  940. if test -f 'nocol-3.0/src/doc/perlnocol.3' -a "${1}" != "-c" ; then 
  941.   echo shar: Will not clobber existing file \"'nocol-3.0/src/doc/perlnocol.3'\"
  942. else
  943.   echo shar: Extracting \"'nocol-3.0/src/doc/perlnocol.3'\" \(4164 characters\)
  944.   sed "s/^X//" >'nocol-3.0/src/doc/perlnocol.3' <<'END_OF_FILE'
  945. X.\" $Header: /home/aggarwal/lsrc/nocol/src/doc/RCS/perlnocol.3,v 1.1 1993/10/28 16:38:03 aggarwal Exp $
  946. X.\"
  947. X.TH PERLNOCOL 3 "Oct 1, 1993"
  948. X.SH NAME
  949. Xperlnocol \- PERL interface to NOCOL
  950. X.SH SYNOPSIS
  951. X.I nocollib.pl
  952. Xis a library of useful PERL routines to facilitate writing PERL monitoring
  953. Xscripts for NOCOL.
  954. X.\"
  955. X.SH DESCRIPTION
  956. X.LP
  957. XThere is a collection of useful 
  958. X.I perl
  959. Xsubroutines in the file
  960. X.I nocollib.pl
  961. Xwhich can be used to write new NOCOL monitors in the perl language.
  962. XSome samples are provided with the distribution (monitors for Novell,
  963. XAppletalk, modem-lines from a Cisco router). Use these as examples to
  964. Xcreate new monitors.
  965. X
  966. XThe PERL interface can be used to parse the output of any Unix program
  967. X(or command) and create NOCOL format data files. The program 
  968. X.B rcisco
  969. Xcan be used to log into a cisco router and run a command on it. The
  970. Xappletalk
  971. X.I armon
  972. Xmonitor runs the command "show apple route" and then parses the output
  973. Xto detect unregistered and missing routes.
  974. X.LP
  975. XThe 
  976. X.I nocollib.pl
  977. Xinterface relies on a list of associative arrays (one for
  978. Xeach field on the nocol EVENT structure\-
  979. X.I $sender, $siteaddr, $varname, etc.
  980. X) which are global in the
  981. Xmain routines. Given an 'index' into this set of arrays, they
  982. Xwork on all these arrays as a set (packing, unpacking, updating, etc.).
  983. XThe index is controlled by the 
  984. X.I main
  985. Xof the programs and is typically an element of the list 
  986. X.IR @items .
  987. X.RS
  988. X.IP &standalone
  989. Xkills any currently running process and writes its new pid to a pidfile.
  990. X.IP &init_event
  991. Xtakes an index and fills in startup default values for each of the
  992. Xassociative arrays mentioned above. It uses the 
  993. X.I $varunits, $varname
  994. Xvalues initially set in the monitor.
  995. X.IP &update_event
  996. Xtakes an index, status (up/down), value and severity as arguments.
  997. XIt then updates the associative arrays (changes the severity, loglevel
  998. Xand logs to
  999. X.IR noclogd )
  1000. Xbased on the level change.
  1001. X.IP &writeevent
  1002. XThis routine takes an index and packs the associative arrays into
  1003. Xa nocol packed structure. It then writes this structure out to 
  1004. Xthe output file.
  1005. X.RE
  1006. X.LP
  1007. XThe monitors are structured as follows:
  1008. X.RS
  1009. X.IP -
  1010. XInitialize the variables such as program to be run, directories, etc.
  1011. X.IP -
  1012. XCreate a subroutine\-
  1013. X.B readconf
  1014. Xto read a configuration file and create a list of items to monitor.
  1015. X.IP -
  1016. XCreate a subroutine\-
  1017. X.B dotest
  1018. Xto do the test. The results of the test can be returned immediately
  1019. Xto the main calling routine (for individual tests) or else pushed into
  1020. Xa list (if extracting multiple parameters in a single run).
  1021. X.IP -
  1022. XCreate a 
  1023. X.I main
  1024. Xroutine which calls the above sub-routines, calls \fIinit_event\fR and then
  1025. Xwrites out the datafile using \fIwriteevent\fR.
  1026. X.RE
  1027. X.LP
  1028. XNote that the status of the items being monitored are stored and tracked
  1029. Xby the perl monitors (and not read from the data-file in each pass as some
  1030. Xother C monitors
  1031. Xdo). The monitors simply overwrite the datafile each time (each pass).
  1032. X.\"
  1033. X.SH INSTALLATION
  1034. X.LP
  1035. X.IP -
  1036. XEdit the variables at the top of the file \-
  1037. X.B nocollib.pl
  1038. Xwhere indicated (more importantly, set
  1039. X.I $nocolroot, $NLOG_HOST
  1040. Xat the minimum).
  1041. X.IP -
  1042. XUse the existing samples (
  1043. X.I armon, modemmon, novellmon
  1044. X) to create new monitors.
  1045. X.IP -
  1046. XYou might need to tweak the
  1047. X.I $event_t
  1048. Xtemplate and change the null padding for the packed
  1049. X.I $event
  1050. Xstructure (see CAVEATS below).
  1051. X.IP -
  1052. XSome of the monitoring agents use 
  1053. X.B rcisco
  1054. Xto log into a remote host and run a command. Edit this program and put
  1055. Xyour router's password in this file. Then install this with mode 750.
  1056. X.LP
  1057. XThe PERL package is available from most popular archives on the Internet (
  1058. X.I ftp.uu.net ftp.netlabs.com
  1059. X).
  1060. X.\"
  1061. X.SH CAVEATS
  1062. X.I C 
  1063. Xcompilers tend to align structure fields on even byte boundaries. In
  1064. Xpacking a structure in PERL, the fields might not align evenly and
  1065. Xnull byte(s) padding might be necessary in the
  1066. X.I $event_t
  1067. Xtemplate.
  1068. X.SH AUTHOR
  1069. X.nf
  1070. XJim Wobus, Syracuse University (jmwobus@mailbox.syr.edu).
  1071. XVikas Aggarwal, JvNCnet, (vikas@jvnc.net).
  1072. X.fi
  1073. X.SH SEE ALSO
  1074. Xnnocol(1) nocol-prog(3) perlnocol(3)
  1075. Xeventselect(8) genmon(8) noclogd(8) nocol-overview(8)
  1076. Xnocol-utility(8) nsmon(8) pingmon(8) portmon(8) 
  1077. Xtpmon(8) trapmon(8)
  1078. X
  1079. END_OF_FILE
  1080.   if test 4164 -ne `wc -c <'nocol-3.0/src/doc/perlnocol.3'`; then
  1081.     echo shar: \"'nocol-3.0/src/doc/perlnocol.3'\" unpacked with wrong size!
  1082.   fi
  1083.   # end of 'nocol-3.0/src/doc/perlnocol.3'
  1084. fi
  1085. if test -f 'nocol-3.0/src/doc/trapmon.8' -a "${1}" != "-c" ; then 
  1086.   echo shar: Will not clobber existing file \"'nocol-3.0/src/doc/trapmon.8'\"
  1087. else
  1088.   echo shar: Extracting \"'nocol-3.0/src/doc/trapmon.8'\" \(2721 characters\)
  1089.   sed "s/^X//" >'nocol-3.0/src/doc/trapmon.8' <<'END_OF_FILE'
  1090. X.\" $Header: /home/aggarwal/lsrc/nocol/src/doc/RCS/trapmon.8,v 1.7 1993/10/28 16:38:03 aggarwal Exp $
  1091. X.\"
  1092. X.TH TRAPMON 8 "June 10, 1992"
  1093. X.SH NAME
  1094. X.B trapmon
  1095. X\- inform
  1096. X.BR nocol (1)
  1097. Xof outstanding SNMP trap messages
  1098. X.SH USAGE
  1099. X.B trapmon [\-v] [\-p] [\-n] [\-l]
  1100. X.TP
  1101. X.B \-p
  1102. XPrint a one-line summary to stderr for each trap received.
  1103. X.TP
  1104. X.B \-n
  1105. XSend output to a file formatted so that
  1106. X.BR nocol (1)
  1107. Xcan read and display it.
  1108. XOne EVENT structure is written for each trap that
  1109. X.B trapmon
  1110. Xreceives.
  1111. X.TP
  1112. X.B \-l
  1113. XSend a one-line summary to the
  1114. X.BR syslogd (8)
  1115. Xfacility, using the same format as the \-p switch.
  1116. X.TP
  1117. X.B \-v
  1118. XSend various debugging output to stdout.  It is unlikely that
  1119. Xthis switch will be of any real use, except in tracking down bugs.
  1120. X.LP
  1121. XMultiple options may be specified.
  1122. X.B trapmon
  1123. X\-pn is equivalent to
  1124. X.B trapmon
  1125. X\-n \-p.
  1126. X.SH DESCRIPTION
  1127. X.LP
  1128. X.B trapmon
  1129. Xwas developed specifically for use with the JvNCnet
  1130. X.BR nocol (1)
  1131. Xsystem- the \-n switch enables reporting designed for
  1132. Xprocessing by
  1133. X.B nocol.
  1134. X.B trapmon
  1135. Xprocesses traps asynchronously using
  1136. X.BR select (2).
  1137. XAs each trap is received, the user is notified
  1138. Xon stderr, through
  1139. X.B syslogd,
  1140. Xor through
  1141. X.BR nocol .
  1142. XWith the \-n option, an EVENT structure is appended
  1143. Xto the output file for each trap, and then
  1144. Xis deleted when 30 minutes later.
  1145. XThis timeout feature ensures that information
  1146. Xabout the traps will not grow without limit and
  1147. Xoverwhelm
  1148. X.B nocol
  1149. Xand the user.
  1150. X.LP
  1151. X.B trapmon
  1152. Xbinds to the SNMP port, so it must be executed by the superuser.
  1153. X.LP
  1154. XFor facilitating 
  1155. X.I enterprise
  1156. Xspecific traps, trapmon appends the value in the 
  1157. X.I specific_type
  1158. Xfield of the trap packet to the word 'Enterprise' in the 
  1159. X.I variable 
  1160. Xfield of the EVENT structure for NOCOL.
  1161. X.SH CAVEATS
  1162. X.LP
  1163. XIf the output file for
  1164. X.B nocol
  1165. Xis on NFS, then 
  1166. X.B trapmon
  1167. Xwill not be able to create the output file unless it is in a world-writable
  1168. Xdirectory.  This is because NFS will not honor superuser privileges on the
  1169. Xremote filesystem where the directory exists. 
  1170. X\fI Thus, the output file must exist on the local machine and not on
  1171. Xan NFS mounted partition.\fR
  1172. X
  1173. XThe 
  1174. X.I enterprise
  1175. Xspecific traps are not converted into text- only the number representing the
  1176. X.I specific_type
  1177. X(from the RFC trap PDU specification) is displayed.
  1178. X.SH AUTHOR
  1179. XDavid Wagner, wagner@jvnc.net, June 10 1992
  1180. X.LP
  1181. X.B trapmon
  1182. Xis derived from snmptrapd, a similar program without
  1183. X.B nocol
  1184. Xsupport that was written by Carnegie Mellon University, and is part of the
  1185. XCMU snmp distribution available via
  1186. X.I anonymous
  1187. Xftp.
  1188. X.SH SEE ALSO
  1189. Xnocol(1) nocol-prog(3) perlnocol(3)
  1190. Xeventselect(8) genmon(8) noclogd(8) nocol-overview(8)
  1191. Xnocol-utility(8) nsmon(8) pingmon(8) portmon(8) 
  1192. Xtpmon(8) trapmon(8)
  1193. XRFC 1065, RFC 1066, RFC 1067
  1194. END_OF_FILE
  1195.   if test 2721 -ne `wc -c <'nocol-3.0/src/doc/trapmon.8'`; then
  1196.     echo shar: \"'nocol-3.0/src/doc/trapmon.8'\" unpacked with wrong size!
  1197.   fi
  1198.   # end of 'nocol-3.0/src/doc/trapmon.8'
  1199. fi
  1200. if test -f 'nocol-3.0/src/include/nocol.h' -a "${1}" != "-c" ; then 
  1201.   echo shar: Will not clobber existing file \"'nocol-3.0/src/include/nocol.h'\"
  1202. else
  1203.   echo shar: Extracting \"'nocol-3.0/src/include/nocol.h'\" \(3694 characters\)
  1204.   sed "s/^X//" >'nocol-3.0/src/include/nocol.h' <<'END_OF_FILE'
  1205. X/*    $Header: /home/aggarwal/lsrc/nocol/src/include/RCS/nocol.h,v 1.13 1993/10/30 03:02:20 aggarwal Exp $    */
  1206. X
  1207. X/* Copyright 1992 JvNCnet, Princeton */
  1208. X
  1209. X/*************************/
  1210. X/*     NOCOL.H          /
  1211. X/***********************/
  1212. X
  1213. X#ifndef __nocol_h
  1214. X# define __nocol_h
  1215. X
  1216. X/* need these include files for inet routines */
  1217. X#include <sys/types.h>
  1218. X#include <stdio.h>
  1219. X#include <errno.h>            /* doesn't define sys_errlist */
  1220. X#ifdef NeXT
  1221. X#  include <sys/malloc.h>
  1222. X#else
  1223. X#  include <malloc.h>
  1224. X#  include <unistd.h>                             /* for access(), lseek()  */
  1225. X#endif    /* NeXT */
  1226. X#include <time.h>
  1227. X#include <sys/time.h>
  1228. X#ifdef sun
  1229. X#  include <sys/socket.h>
  1230. X#endif
  1231. X#include <netinet/in.h>
  1232. X#include <arpa/inet.h>
  1233. X
  1234. X#include <sys/file.h>
  1235. X#include <sys/stat.h>
  1236. X#include <fcntl.h>
  1237. X
  1238. X
  1239. Xextern char *sys_errlist[] ;
  1240. X
  1241. Xtypedef char BYTE;        /* an 8-bit field */
  1242. X
  1243. X#define MAXPROGNM    12    /* Name of monitoring program */
  1244. X#define    MAXNMLEN    16    /* For site's name, can be nickname */
  1245. X#define MAXADDRLEN    128    /* Ok for IP, decnet, OSI */
  1246. X#define MAXCOMMENT    16    /* For comments that the programs might have */
  1247. X#define MAXTAGLEN    8    /* For classifying/troubleshooting ? */
  1248. X
  1249. X/* data structure of NOCOL event message */
  1250. X
  1251. X/* site identifier */
  1252. Xtypedef struct 
  1253. X{
  1254. X    char    name[MAXNMLEN];        /* site name (can also be a pseudo) */ 
  1255. X    char    addr[MAXADDRLEN];    /* Okay for IP, DECnet, OSI */
  1256. X/*    char    tag[MAXTAGLEN];        /* For tagging sites. Optional */
  1257. X} SITE;    
  1258. X
  1259. X/* problem identifier */
  1260. X/* typedef struct
  1261. X/* {
  1262. X/*    unsigned char    class:8;     problem class */
  1263. X/*    short         id;         problem id from 001 to 999
  1264. X/*                     for each class */
  1265. X/* } PROB;
  1266. X*/
  1267. X
  1268. X/* variable info */
  1269. Xtypedef struct
  1270. X{
  1271. X    char    name[MAXNMLEN];        /* name or keyword of variable */
  1272. X    u_long    value;            /* variable value */
  1273. X    u_long    threshold;        /* variable threshold, if applicable */
  1274. X    char    units[8];        /* units of variable (pkts, ms) */
  1275. X} VAR;
  1276. X
  1277. X/* event format */
  1278. Xtypedef struct 
  1279. X{
  1280. X    char    sender[MAXPROGNM];    /* 8 bytes of sender name */
  1281. X    SITE        site;        /* site identifier */
  1282. X    VAR            var;        /* variable info */
  1283. X    unsigned char    mon:8;        /* 1 to 12; can be reduced to 4 bits */
  1284. X    unsigned char    day:8;        /* 1 to 31; can be reduced to 5 bits */
  1285. X    unsigned char    hour:8;        /* 0 to 23; can be reduced to 5 bits */
  1286. X    unsigned char    min:8;        /* 0 to 59; can be reduced to 6 bits */
  1287. X    unsigned char    severity:8;    /* event severity; need only 2 bits */
  1288. X    unsigned char    loglevel:8;    /* for logging; need only 2 bits */
  1289. X    unsigned char    nocop:8;    /* operations flag indicating STATE */
  1290. X/*    char    comment[MAXCOMMENT];    /* Generic comment, for future... */
  1291. X} EVENT;
  1292. X
  1293. X/* Event severities. */
  1294. X#define E_CRITICAL    1
  1295. X#define E_ERROR        2
  1296. X#define E_WARNING    3
  1297. X#define E_INFO        4
  1298. X
  1299. X/* Text used to refer to severity levels. First is null since start with 1 */
  1300. Xstatic char *severity_txt[] = {
  1301. X    "BAD-0", "Critical", "Error", "Warning", "Info", "BAD-5"} ;
  1302. X
  1303. X/* 'nocop' flags indicating various 'STATE's that a site can be in */
  1304. X
  1305. X#define n_UP        0x01
  1306. X#define n_DOWN        0x02
  1307. X#define n_UNKNOWN    0x04            /* not tested yet ? */
  1308. X#define n_TEST        0x08            /* Site in test mode */
  1309. X#define n_NODISPLAY    0x10            /* Ignore while displaying */
  1310. X
  1311. X/*
  1312. X * Some flag operations on mask 'm'. Since UP, DOWN, UNKNOWN are mutually
  1313. X * exclusive, this macro sets the desired mask and clears the others
  1314. X * (No, the DOUN is not a typo, it stands for DOwn and UNknown
  1315. X */
  1316. X#define SETF_UPDOUN(mask, f)    ( (mask & ~(n_UP | n_DOWN | n_UNKNOWN)) | f )
  1317. X
  1318. Xstruct nocop_txt_s
  1319. X{
  1320. X    int        v ;
  1321. X    char    *str ;        /* Text used to refer to nocop flags */
  1322. X};
  1323. Xstatic struct nocop_txt_s nocop_txt[] = {
  1324. X  {n_UP, "up"},
  1325. X  {n_DOWN, "down"},
  1326. X  {n_UNKNOWN, "unknown"},
  1327. X  {n_TEST, "test"},
  1328. X  {n_NODISPLAY ,"nodisplay"},
  1329. X  {0, ""}
  1330. X} ;
  1331. X
  1332. X
  1333. X
  1334. X#endif    /* __nocol_h  */
  1335. END_OF_FILE
  1336.   if test 3694 -ne `wc -c <'nocol-3.0/src/include/nocol.h'`; then
  1337.     echo shar: \"'nocol-3.0/src/include/nocol.h'\" unpacked with wrong size!
  1338.   fi
  1339.   # end of 'nocol-3.0/src/include/nocol.h'
  1340. fi
  1341. if test -f 'nocol-3.0/src/include/trapmon.h' -a "${1}" != "-c" ; then 
  1342.   echo shar: Will not clobber existing file \"'nocol-3.0/src/include/trapmon.h'\"
  1343. else
  1344.   echo shar: Extracting \"'nocol-3.0/src/include/trapmon.h'\" \(4009 characters\)
  1345.   sed "s/^X//" >'nocol-3.0/src/include/trapmon.h' <<'END_OF_FILE'
  1346. X/*
  1347. X * $Header: /home/aggarwal/lsrc/nocol/src/include/RCS/trapmon.h,v 1.8 1993/11/04 07:40:13 aggarwal Exp $
  1348. X */
  1349. X
  1350. X#include <sys/types.h>
  1351. X#include <netinet/in.h>
  1352. X#include <stdio.h>
  1353. X#include <time.h>
  1354. X#include <sys/time.h>
  1355. X#include <errno.h>
  1356. X#include <syslog.h>
  1357. X#include <fcntl.h>
  1358. X#include <string.h>
  1359. X#include <sys/socket.h>
  1360. X#include <netdb.h>
  1361. X
  1362. X#include "snmp.h"
  1363. X#include "snmp_impl.h"
  1364. X#include "asn1.h"
  1365. X#include "snmp_api.h"
  1366. X#include "snmp_client.h"
  1367. X
  1368. X#include "nocol.h"                /* For O_NETMON output */
  1369. X
  1370. X#ifndef HAVE_FD_MACROS
  1371. X# ifdef BSD4_3                    /* BSD4.3 already has these */
  1372. X#  define HAVE_FD_MACROS
  1373. X# endif
  1374. X# ifdef FD_SET
  1375. X#  define HAVE_FD_MACROS
  1376. X# endif
  1377. X#endif
  1378. X
  1379. X/* Macros for use with snmp_select_info() and select() */
  1380. X#ifndef HAVE_FD_MACROS
  1381. Xtypedef long    fd_mask;
  1382. X#define NFDBITS (sizeof(fd_mask) * NBBY)        /* bits per mask */
  1383. X#define FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
  1384. X#define FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
  1385. X#define FD_ISSET(n, p)  ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
  1386. X#define FD_ZERO(p)      bzero((char *)(p), sizeof(*(p)))
  1387. X#endif /*end of #ifdef HAVE_FD_MACROS */
  1388. X
  1389. X/* These #define's handle 4.2 systems without additional syslog facilities. */
  1390. X#ifndef LOG_CONS
  1391. X#define LOG_CONS        0       /* Don't bother if not defined... */
  1392. X#endif
  1393. X#ifndef LOG_LOCAL0
  1394. X#define LOG_LOCAL0      0
  1395. X#endif
  1396. X
  1397. X
  1398. X/* Output data dir for the NOCOL style output */
  1399. X#ifndef DATADIR
  1400. X#define DATADIR        "../../data"
  1401. X#endif
  1402. X
  1403. X/*
  1404. X** SNMP_TRAP_MAX is the largest valid SNMP_TRAP_* number
  1405. X** SNMP_TRAP_MAX + 1 is the canonical unknown/invalid trap number
  1406. X** This really belongs in "snmp.h" with the SNMP_TRAP_* define's there
  1407. X#define SNMP_TRAP_MAX    0x6
  1408. X
  1409. X/*
  1410. X * Describe all the possible traps here and their severity levels here.
  1411. X * Note that the location of the traps in the array depends on the int
  1412. X * value assigned to the various trap types in 'snmp.h'
  1413. X */
  1414. X
  1415. Xstruct t_desc {
  1416. X    char  *tname ;        /* Trap name */
  1417. X    int   tseverity ;        /* Trap severity as described in nocol.h */
  1418. X    char  *tseverity_str ;    /* Severity description strings */
  1419. X    int   nocop ;        /* Operation status n_UP, n_DOWN, n_UNKNOWN */
  1420. X    int   loglevel ;        /* For noclogd logging level */
  1421. X} ;
  1422. X
  1423. Xstruct t_desc trap_desc[] = {
  1424. X  { "Cold_Start", E_WARNING, "Warning", n_UP, E_WARNING },    /* trap 0 */
  1425. X  { "Warm_Start", E_WARNING, "Warning", n_UP, E_WARNING },    /* trap 1 */
  1426. X  { "Link_Down",  E_ERROR,   "ERROR", n_DOWN, E_ERROR},        /* trap 2 */
  1427. X  { "Link_Up",    E_ERROR,   "ERROR", n_UP, E_ERROR},        /* trap 3 */
  1428. X  { "Auth_Failure", E_WARNING, "Warning", n_UP, E_WARNING},    /* trap 4 */
  1429. X  { "EGP_Peer_Loss", E_CRITICAL, "CRITICAL", n_DOWN, E_CRITICAL}, /* trap 5 */
  1430. X  { "Enterprise", E_WARNING, "Warning", n_UNKNOWN, E_WARNING},    /* trap 6 */
  1431. X  { "Unknown_Type", E_WARNING, "Warning", n_UNKNOWN, E_WARNING}    /* trap 7 */
  1432. X} ;
  1433. X
  1434. X
  1435. X
  1436. X/*
  1437. X** Possible options:
  1438. X**  O_NETMON:    output EVENT structures to file for use with netmon
  1439. X**  O_LOG:    output to syslog()
  1440. X**  O_PRINT:    output to stderr
  1441. X**  O_DEBUG:    debugging output to stdout
  1442. X** See the 'options' global variable below
  1443. X*/
  1444. X#define O_NETMON    0x1
  1445. X#define O_LOG        0x2
  1446. X#define O_PRINT        0x4
  1447. X#define O_DEBUG        0x8
  1448. X
  1449. X/*
  1450. X * Timeout for each EVENT in seconds - currently set to 30 minutes.
  1451. X * Trap events older than this will be deleted from the data file.
  1452. X */
  1453. X#define TIME_TO_LIVE    (30*60)        /* convert to seconds */
  1454. X
  1455. X/* Timeout for select() in seconds - currently set to 5 minutes */
  1456. X#define SELECT_TIMEOUT    (5*60)
  1457. X
  1458. X#define MAX_PATH_LEN    256            /* Longest path expected */
  1459. X#define DATAFILE_MODE    0664            /* Mode for EVENT file */
  1460. X#define OUTPUT_EXTENSION "-output"        /* Extension for EVENT file */
  1461. X#define MAX_TRAPS    256            /* Max # of unresolved traps */
  1462. X
  1463. Xextern int    errno;
  1464. Xint        snmp_dump_packet = 0;
  1465. Xint        options;            /* Command line options */
  1466. Xchar        *progname;            /* Program name, no path */
  1467. Xchar        datafname[MAX_PATH_LEN];    /* Filename for O_NETMON */
  1468. Xtime_t        die_at[MAX_TRAPS];        /* When this EVENT times out */
  1469. Xint        numtraps;            /* # of outstanding EVENTs */
  1470. END_OF_FILE
  1471.   if test 4009 -ne `wc -c <'nocol-3.0/src/include/trapmon.h'`; then
  1472.     echo shar: \"'nocol-3.0/src/include/trapmon.h'\" unpacked with wrong size!
  1473.   fi
  1474.   # end of 'nocol-3.0/src/include/trapmon.h'
  1475. fi
  1476. if test -f 'nocol-3.0/src/lib/standalone.c' -a "${1}" != "-c" ; then 
  1477.   echo shar: Will not clobber existing file \"'nocol-3.0/src/lib/standalone.c'\"
  1478. else
  1479.   echo shar: Extracting \"'nocol-3.0/src/lib/standalone.c'\" \(3663 characters\)
  1480.   sed "s/^X//" >'nocol-3.0/src/lib/standalone.c' <<'END_OF_FILE'
  1481. X/*+     $Header: /home/aggarwal/lsrc/nocol/src/lib/RCS/standalone.c,v 1.7 1993/10/02 05:26:53 aggarwal Exp $
  1482. X *
  1483. X */
  1484. X
  1485. X/* Copyright 1992 JvNCnet, Princeton */
  1486. X
  1487. X/*+
  1488. X**
  1489. X** FUNCTION:
  1490. X**
  1491. X**    Kill any other process and write the present PID into the
  1492. X** PidFile. If cannot write to the file or if the file is locked
  1493. X** by another process, it returns a value of -1 (in which case the
  1494. X** calling program should EXIT).
  1495. X**
  1496. X** It assumes that the PidFile is "program.pid", where the pointer
  1497. X** to the string "program" is passed to it.
  1498. X**
  1499. X** (Observe that unless the program name has been stripped of the 
  1500. X**  path, the pid file is created in the same directory as the
  1501. X**  program).
  1502. X**
  1503. X**  Method:
  1504. X**        See if pid file exists, create if none
  1505. X**            try to lock
  1506. X**        if cannot lock 
  1507. X**           kill process
  1508. X**           if (cannot kill)
  1509. X**             return (-1)
  1510. X**           else
  1511. X**             lock file
  1512. X**        write pid, return to caller
  1513. X**
  1514. X** NOTE:
  1515. X**     I *do* know about the 'access' system call for the existability
  1516. X** of a file. It just tended to screw up on the sun, so I used the simple
  1517. X** 'fopen' call to test if the file exists.
  1518. X**/
  1519. X
  1520. X/*
  1521. X * $Log: standalone.c,v $
  1522. X * Revision 1.7  1993/10/02  05:26:53  aggarwal
  1523. X * Now requires path to the PIDfile. Also assumes that 'prog' is the
  1524. X * name of the program being run.
  1525. X *
  1526. X * Revision 1.6  1992/06/18  21:15:00  aggarwal
  1527. X * Completely rewritten. No fancy stuff anymore (using fcntl or all
  1528. X * that).
  1529. X *
  1530. X * 
  1531. X * Revision 1.3  90/06/15  11:58:40  network
  1532. X * After sending out kill signal, wait for a while so that
  1533. X * the process can die and release the file.
  1534. X *
  1535. X */
  1536. X#include <stdio.h>
  1537. X#include <signal.h>                /* signal numbers    */
  1538. X#include <sys/file.h>
  1539. X#include <errno.h>
  1540. X
  1541. X#ifndef MAXLINE
  1542. X#define MAXLINE    256
  1543. X#endif
  1544. X
  1545. Xstandalone (prognm_pidf)
  1546. X     char *prognm_pidf;            /* Path of PID file without suffix */
  1547. X{
  1548. X    FILE *pidf ;
  1549. X    int oldpid = 0, newpid = 0;
  1550. X    int fd ;
  1551. X    char *pidfile, *prog;
  1552. X    char hostname[MAXLINE], thishostname[MAXLINE] ;
  1553. X    
  1554. X    pidfile = (char *)malloc(strlen(prognm_pidf) + 6) ;
  1555. X    sprintf(pidfile, "%s.pid\0", prognm_pidf);    /* add suffix to name    */
  1556. X    if ((prog = (char *)strrchr (prognm_pidf, '/')) == NULL)
  1557. X      prog = prognm_pidf ;            /* no path in name */
  1558. X    else
  1559. X      prog++ ;                    /* skip leading '/' */
  1560. X    
  1561. X    gethostname(thishostname, sizeof(thishostname) -1) ;
  1562. X    thishostname[MAXLINE - 1] = '\0' ;
  1563. X
  1564. X    if ( (pidf =fopen (pidfile, "r")) != NULL)    /* file exists...    */
  1565. X    {
  1566. X    if (fscanf(pidf, "%d %s", &oldpid, hostname) == EOF)
  1567. X    {
  1568. X        fprintf(stderr, "(standalone): fscanf ");
  1569. X        perror(pidfile) ;            /* couldn't read */
  1570. X        return (-1);
  1571. X    }
  1572. X    fclose(pidf);
  1573. X
  1574. X    if (strcmp(thishostname, hostname) != 0)    /* wrong host */
  1575. X    {
  1576. X        fprintf(stderr,
  1577. X            "(standalone) %s: Program probably running on '%s'\n",
  1578. X            prog, hostname) ;
  1579. X        fprintf(stderr, "Kill and delete '%s' file and restart\n",pidfile);
  1580. X        return (-1) ;
  1581. X    }
  1582. X    else                    /* on proper host */
  1583. X    {
  1584. X        if (kill (oldpid, SIGKILL) != 0 && errno != ESRCH)
  1585. X        {
  1586. X        fprintf(stderr,
  1587. X            "(standalone) %s: Couldn't kill earlier process\n",
  1588. X            prog);
  1589. X        perror("signal");
  1590. X        return (-1) ;
  1591. X        }
  1592. X        else
  1593. X          sleep (5) ;        /* Let other process die */
  1594. X    }
  1595. X    }            /* end if (pidfile could be opened) */
  1596. X
  1597. X    /*
  1598. X     * Here only if all other processes have been killed
  1599. X     */
  1600. X
  1601. X    newpid=getpid();
  1602. X    if ( (pidf = fopen(pidfile, "w")) == NULL)    /* create file    */
  1603. X    {
  1604. X    fprintf(stderr, "(standalone): fopen ");
  1605. X    perror(pidfile);    
  1606. X    return(-1);
  1607. X    }
  1608. X    fprintf (pidf,  "%d\n%s\n", newpid, thishostname);    /* Store present pid */
  1609. X    fflush(pidf);
  1610. X    fclose(pidf) ;
  1611. X    fprintf(stderr, "(%s).. locked pid-file, started new process\n", prog);
  1612. X    
  1613. X    return (0) ;
  1614. X}
  1615. END_OF_FILE
  1616.   if test 3663 -ne `wc -c <'nocol-3.0/src/lib/standalone.c'`; then
  1617.     echo shar: \"'nocol-3.0/src/lib/standalone.c'\" unpacked with wrong size!
  1618.   fi
  1619.   # end of 'nocol-3.0/src/lib/standalone.c'
  1620. fi
  1621. if test -f 'nocol-3.0/src/netmon/fill_window.c' -a "${1}" != "-c" ; then 
  1622.   echo shar: Will not clobber existing file \"'nocol-3.0/src/netmon/fill_window.c'\"
  1623. else
  1624.   echo shar: Extracting \"'nocol-3.0/src/netmon/fill_window.c'\" \(4125 characters\)
  1625.   sed "s/^X//" >'nocol-3.0/src/netmon/fill_window.c' <<'END_OF_FILE'
  1626. X/*
  1627. X**    $Header: /home/aggarwal/lsrc/nocol/src/netmon/RCS/fill_window.c,v 1.7 1993/10/30 03:52:08 aggarwal Exp $
  1628. X*/
  1629. X
  1630. X/*+ 
  1631. X**     This function fills the window given with files from the
  1632. X** specified directory pointer. A pointer to the funtion that is to be
  1633. X** called to display one line from the data files is passed. This is
  1634. X** done to make this function usable for both the EVENT window as well
  1635. X** as the MESSAGES window.
  1636. X**
  1637. X** LOGIC
  1638. X**    1) Skip over any file that begins with a "." or named 'core'
  1639. X**    2) Reset to start of window (needed since we are using WFULL
  1640. X**       to decide when to stop putting out lines.
  1641. X**    3) Get next file in directory
  1642. X**       - if directory type then skip
  1643. X**            - open file
  1644. X**    4) If end of directory, close and return 1
  1645. X**    5) If not FULL, call display_function
  1646. X**       else return(0)
  1647. X**    6) If end of file,
  1648. X**        - close file
  1649. X**        - open next file
  1650. X**        - if end of dir, clrtobot, return(1)
  1651. X**
  1652. X** 
  1653. X** RETURN VALUE
  1654. X**    1 if all files in directory are displayed.
  1655. X**    0 if all files have not yet been displayed.
  1656. X**/
  1657. X
  1658. X
  1659. X/*
  1660. X *
  1661. X *    $Log: fill_window.c,v $
  1662. X * Revision 1.7  1993/10/30  03:52:08  aggarwal
  1663. X * Now uses dirent(). Deleted include dir.h
  1664. X *
  1665. X * Revision 1.6  1993/10/05  04:17:41  aggarwal
  1666. X * Now skips over 'core' files.
  1667. X *
  1668. X * Revision 1.5  1992/06/18  21:03:22  aggarwal
  1669. X * Cleaned up for releasing.
  1670. X *
  1671. X * Revision 1.4  1992/04/22  22:59:58  aggarwal
  1672. X * Lot of cleaning up for releasing. Organized things right.
  1673. X *
  1674. X * Revision 1.3  1990/05/23  17:21:21  aggarwal
  1675. X * Uncommented wmove() - see preamble (comments).
  1676. X *
  1677. X * Revision 1.2  90/05/13  22:27:02  aggarwal
  1678. X * Commented out the line for resetting the window position to (0,0) 
  1679. X * since that should depend on the window being operated upon - the msg
  1680. X * win can scroll so I don't want to reset the cursor position for the 
  1681. X * msg window. Have moved the line to the event_dpy.c module instead.
  1682. X * Added ' fstat' so that a directory is skipped and not treated as a 
  1683. X * data file. 
  1684. X * 
  1685. X * Revision 1.1  90/03/09  13:05:47  aggarwal
  1686. X * Initial revision
  1687. X * 
  1688. X */
  1689. X
  1690. X#include    "netmon.h"
  1691. X
  1692. X#define WFULL(w)      (w->_cury == (w->_maxy - 1)) ? 1:0
  1693. X
  1694. Xfill_window(win, dirp, dir, pcurfd, dpy_func)
  1695. X     WINDOW *win;            /* Window to be filled        */
  1696. X     char *dir ;            /* Name of the directory    */
  1697. X     DIR *dirp;                /* opened directory pointer    */
  1698. X     int *pcurfd;            /* Present opened file desc    */
  1699. X     int (*dpy_func)();            /* Display function        */
  1700. X{
  1701. X    struct dirent *direntry ;
  1702. X    char file[MAXLINE];
  1703. X    int opennew = 0;                /* boolean to open file    */
  1704. X
  1705. X
  1706. X    wmove(win, 0, 0);                /* reset to start pos    */
  1707. X    
  1708. X    if (*pcurfd == 0)                /* No file open...    */
  1709. X      opennew = 1 ;
  1710. X
  1711. Xopen_file:
  1712. X    while (opennew)            /* open new file until successful */
  1713. X    {
  1714. X    struct stat buf ;        /* for fstat */
  1715. X
  1716. X    if (*pcurfd > 0)        /* close any currently open file */
  1717. X      close(*pcurfd);
  1718. X
  1719. X    if ((direntry = readdir(dirp)) == NULL)
  1720. X    {                    /* All files are done    */
  1721. X        wclrtobot(win);            /* Clear win to bottom    */
  1722. X        *pcurfd = 0;            /* reset to zero    */
  1723. X        return (1);                /* All files displayed    */
  1724. X    }
  1725. X
  1726. X    /* name begins with a dot or 'core' or is not a file */
  1727. X    if (*(direntry->d_name) == '.' || strcmp(direntry->d_name, "core") ==0)
  1728. X      goto open_file ;                  /* ...so skip it    */
  1729. X
  1730. X    sprintf (file, "%s/%s", (char *)dir, (char *)direntry->d_name);
  1731. X    
  1732. X    if ((*pcurfd = open(file, O_RDONLY)) == -1)    /* error */
  1733. X    {
  1734. X        wprintw (aw.wmsg,
  1735. X             "\nERROR fill_win(open): '%s'- %s",
  1736. X             direntry->d_name, sys_errlist[errno]);
  1737. X        continue ;
  1738. X    }
  1739. X
  1740. X    /*
  1741. X     * Here if safely opened data file
  1742. X     */
  1743. X    fstat (*pcurfd, &buf);        /* Get info about fd    */
  1744. X    if ((buf.st_mode & S_IFMT) == S_IFDIR)    /* It is a dir    */
  1745. X    {                    /* ..so open another    */
  1746. X        close(*pcurfd);
  1747. X        goto open_file ;
  1748. X    }
  1749. X
  1750. X    opennew = 0;            /* Don't open another    */
  1751. X    if (options & debug)
  1752. X      wprintw (aw.wmsg, 
  1753. X           "\n(DEBUG) fill_win: Opened file %s... ", direntry->d_name);
  1754. X
  1755. X    }        /* end:  while opennew    */
  1756. X
  1757. X    while (!(WFULL(win)))
  1758. X      if (dpy_func(*pcurfd, win) == 0)        /* end of file        */
  1759. X      {
  1760. X      opennew = 1;                /* open another file    */
  1761. X      goto open_file ;
  1762. X      }
  1763. X    return (0) ;                /* Window full        */
  1764. X
  1765. X}                        /* end: fill_window    */
  1766. END_OF_FILE
  1767.   if test 4125 -ne `wc -c <'nocol-3.0/src/netmon/fill_window.c'`; then
  1768.     echo shar: \"'nocol-3.0/src/netmon/fill_window.c'\" unpacked with wrong size!
  1769.   fi
  1770.   # end of 'nocol-3.0/src/netmon/fill_window.c'
  1771. fi
  1772. if test -f 'nocol-3.0/src/netmon/parse_input.c' -a "${1}" != "-c" ; then 
  1773.   echo shar: Will not clobber existing file \"'nocol-3.0/src/netmon/parse_input.c'\"
  1774. else
  1775.   echo shar: Extracting \"'nocol-3.0/src/netmon/parse_input.c'\" \(3223 characters\)
  1776.   sed "s/^X//" >'nocol-3.0/src/netmon/parse_input.c' <<'END_OF_FILE'
  1777. X/*+ 
  1778. X** $Header: /home/aggarwal/lsrc/nocol/src/netmon/RCS/parse_input.c,v 1.5 1992/06/18 21:06:55 aggarwal Exp $
  1779. X**/
  1780. X
  1781. X/* Copyright 1992 JvNCnet, Princeton */
  1782. X
  1783. X/*+ 
  1784. X** Parse the user input and act accordingly (call appropriate
  1785. X** function). Note that it might modify the values of 'options' and 'level'
  1786. X** which are defined in 'netmon.h'
  1787. X**/
  1788. X
  1789. X/*
  1790. X * $Log: parse_input.c,v $
  1791. X * Revision 1.5  1992/06/18  21:06:55  aggarwal
  1792. X * Updated for search filter.
  1793. X *
  1794. X * Revision 1.4  1992/04/23  15:43:42  aggarwal
  1795. X * Added ^S and ^Q also.
  1796. X *
  1797. X * Revision 1.3  1992/04/22  22:59:58  aggarwal
  1798. X * Lot of cleaning up for releasing. Organized things right.
  1799. X *
  1800. X * Revision 1.2  1990/04/17  17:28:36  network
  1801. X * Added the 'N' option for "netlog" ( it had better be in your
  1802. X * path...).
  1803. X *
  1804. X * Revision 1.1  90/03/09  16:25:51  aggarwal
  1805. X * Initial revision
  1806. X * 
  1807. X * 
  1808. X */
  1809. X
  1810. X#include    "netmon.h"
  1811. X#include    <ctype.h>
  1812. X
  1813. Xparse_input(response)
  1814. X     char response;
  1815. X{
  1816. X    extern int options, level;            /* defined in netmon.h    */
  1817. X    extern bool frozen;
  1818. X    extern struct allwins aw;            /* defined in netmon.h    */
  1819. X    int poll_input(), newresponse;
  1820. X
  1821. X    switch (response)
  1822. X    {
  1823. X     case 'b':                    /* toggle beep/bell    */
  1824. X    options = options ^ quiet ;
  1825. X    break ;
  1826. X
  1827. X     case 'c':                     /* Contract event win    */
  1828. X    --eventsz;
  1829. X    endwin();
  1830. X    all_doer();
  1831. X    break ;
  1832. X
  1833. X     case 'd':                    /* toggle debug mode    */
  1834. X    options = options ^ debug;        /* XOR the debug bit    */
  1835. X    wprintw(aw.wmsg, "\n Debug mode ");
  1836. X    if ( options & debug)
  1837. X      wprintw(aw.wmsg, "on");
  1838. X    else
  1839. X      wprintw(aw.wmsg, "off");
  1840. X    display_screenful() ;
  1841. X    break ;
  1842. X
  1843. X     case 'w':
  1844. X     case 'e':                    /* toggle wide mode    */
  1845. X    options = options ^ emode ;        /* XOR the extended bit    */
  1846. X    endwin ();
  1847. X    all_doer() ;
  1848. X    break ;
  1849. X
  1850. X     case CTRL('s'): case CTRL('q'):
  1851. X     case 'f':                    /* Freeze display    */
  1852. X    frozen = !frozen ;            /* Invert the bit    */
  1853. X    msgtitle_dpy(aw.wmsgtitle);        /* To indicate frozen    */
  1854. X    display_screenful() ;            /* Show on terminal    */
  1855. X    parse_input(poll_input());        /* To redisplay present    */
  1856. X    break ;
  1857. X
  1858. X     case 'l':                    /* new display level    */
  1859. X    wprintw(aw.wmsg, "\nEnter new level [%d-%d]", E_CRITICAL, E_INFO);
  1860. X    display_screenful();
  1861. X    newresponse = poll_input() - '0';    /* character to number    */
  1862. X    if (newresponse >= E_CRITICAL && newresponse <= E_INFO )
  1863. X      level = newresponse ;
  1864. X    wprintw(aw.wmsg, " %d OK", level);
  1865. X    display_screenful() ;
  1866. X    break ;
  1867. X
  1868. X      case 'q':                    /* quit            */
  1869. X    done ();
  1870. X    break ;
  1871. X
  1872. X      case '?': case 'h':            /* Help page        */
  1873. X    help_page();
  1874. X    display_screenful();            /* Main window again    */
  1875. X    break;
  1876. X    
  1877. X#ifdef NETLOG
  1878. X      case 'n':                               /* Run NETLOG           */
  1879. X    endwin();
  1880. X    system ("netlog");                      /* better be in path    */
  1881. X    wrefresh(curscr);
  1882. X    break;
  1883. X#endif
  1884. X     case CTRL('l'):
  1885. X     case 'r':                    /* redraw screen    */
  1886. X    wrefresh (curscr);
  1887. X    parse_input (poll_input());
  1888. X    break ;
  1889. X
  1890. X     case 's':                    /* search filter */
  1891. X     case '/': case '|':
  1892. X    read_filter();
  1893. X    msgtitle_dpy(aw.wmsgtitle);        /* indicate filter in effect */
  1894. X    display_screenful();
  1895. X    break ;
  1896. X
  1897. X     case 'x':                    /* Expand window    */
  1898. X    ++eventsz;
  1899. X    endwin();
  1900. X    all_doer();
  1901. X    break;
  1902. X
  1903. X     default:                    /* return for next scr    */
  1904. X    break ;
  1905. X    }                            /* End switch()        */
  1906. X
  1907. X    return (1);    
  1908. X}                        /* End:  parse_input()    */
  1909. END_OF_FILE
  1910.   if test 3223 -ne `wc -c <'nocol-3.0/src/netmon/parse_input.c'`; then
  1911.     echo shar: \"'nocol-3.0/src/netmon/parse_input.c'\" unpacked with wrong size!
  1912.   fi
  1913.   # end of 'nocol-3.0/src/netmon/parse_input.c'
  1914. fi
  1915. if test -f 'nocol-3.0/src/netmon/read_filter.c' -a "${1}" != "-c" ; then 
  1916.   echo shar: Will not clobber existing file \"'nocol-3.0/src/netmon/read_filter.c'\"
  1917. else
  1918.   echo shar: Extracting \"'nocol-3.0/src/netmon/read_filter.c'\" \(3636 characters\)
  1919.   sed "s/^X//" >'nocol-3.0/src/netmon/read_filter.c' <<'END_OF_FILE'
  1920. X/*
  1921. X * $Header: /home/aggarwal/lsrc/nocol/src/netmon/RCS/read_filter.c,v 1.2 1993/10/30 03:54:31 aggarwal Exp $
  1922. X */
  1923. X
  1924. X/* Copyright 1993 JvNCnet, Global Enterprise Services */
  1925. X
  1926. X/*
  1927. X * Creates a new window and reads in the user entered string which is used
  1928. X * as the filter. All EVENT structures that match this pattern will then
  1929. X * be displayed by the NOCOL display program
  1930. X *
  1931. X * AUTHOR
  1932. X *    David Wagner, wagner@jvnc.net, June 8, 1992
  1933. X *
  1934. X */
  1935. X
  1936. X/*
  1937. X * $Log: read_filter.c,v $
  1938. X * Revision 1.2  1993/10/30  03:54:31  aggarwal
  1939. X * using _tty.sg_erase is kinda non-portable. Using erasechar() instead
  1940. X *
  1941. X * Revision 1.1  1992/06/18  21:08:29  aggarwal
  1942. X * Initial revision
  1943. X *
  1944. X */
  1945. X
  1946. X#include "netmon.h"
  1947. X
  1948. X#define MAXLINELEN    256            /* Max length of new pattern */
  1949. X/*
  1950. X * Global variables
  1951. X */
  1952. Xchar pattern[MAXLINELEN];        /* Save the pattern */
  1953. Xint isdefined_pattern=0;        /* Is pattern specified yet? */
  1954. X
  1955. X
  1956. X/*+    read_filter
  1957. X ** Creates a new window and reads in a new pattern string for filtering
  1958. X ** out unwanted information.
  1959. X ** Compiles that pattern for later use by filter().
  1960. X */
  1961. X
  1962. Xread_filter()
  1963. X{
  1964. X  WINDOW *npatwin;                /* Where to get pattern from */
  1965. X
  1966. X  npatwin = newwin(0,0,0,0);            /* Create new window */
  1967. X  touchwin(npatwin);                /* Bring it to the front */
  1968. X  wstandout(npatwin);                /* Print the title header */
  1969. X  mvwprintw(npatwin, 0, (int) (COLS/2 - 9), "NEW FILTER PATTERN\n\n");
  1970. X  wstandend(npatwin);
  1971. X
  1972. X  if (isdefined_pattern) {
  1973. X    /*
  1974. X    ** There is a pattern compiled already - use it as the default,
  1975. X    ** and let the user edit it as the starting point for a new one.
  1976. X    */
  1977. X    wprintw(npatwin, "Use ^U to erase filter\n");
  1978. X    wprintw(npatwin, "Enter filter (<word> [&] [|] <word>..): %s", pattern);
  1979. X    wrefresh(npatwin);
  1980. X    get_filter(npatwin, pattern, strlen(pattern));
  1981. X  } else {
  1982. X    /*
  1983. X    ** This is the first call to new_pattern(), so there is no
  1984. X    ** saved pattern available.
  1985. X    */
  1986. X    wprintw(npatwin, "Use ^U to erase filter\n");
  1987. X    wprintw(npatwin, "Enter filter (<word> [&] [|] <word>..): ");
  1988. X    wrefresh(npatwin);
  1989. X    get_filter(npatwin, pattern, 0);
  1990. X  }
  1991. X
  1992. X  if (*pattern == '\0')
  1993. X    isdefined_pattern = 0;            /* clear pattern ? */
  1994. X  else
  1995. X  {
  1996. X      isdefined_pattern = 1;            /* Remember we set pattern[] */
  1997. X      wprintw(npatwin, "\n\nFilter accepted!\n");    /* Notify the user. */
  1998. X  }
  1999. X  wrefresh(npatwin);
  2000. X
  2001. X  compile_pattern(pattern);            /* Defined in filter.c */
  2002. X  werase(npatwin);            /* Return to the main display */
  2003. X}            /* end:   read_filter */
  2004. X
  2005. X/*
  2006. X** Takes the string listed in pat[] as the starting point for a
  2007. X** new pattern and allows the user to edit that one to create a new one.
  2008. X** The backspace and erase keys are accepted - right now there is no
  2009. X** fancy editing.
  2010. X**
  2011. X** Places the newly entered string into pat[] upon returning.
  2012. X*/
  2013. Xget_filter(w, pat, patlen)
  2014. X     WINDOW *w;
  2015. X     char pat[MAXLINELEN];
  2016. X     int patlen;
  2017. X{
  2018. X  int i;
  2019. X
  2020. X  i = patlen;
  2021. X
  2022. X  while ((pat[i]=wgetch(w)) != '\n')        /* Read one char at a time */
  2023. X      if (i>0 && (pat[i]=='\b' || pat[i]==erasechar())) 
  2024. X      {
  2025. X      wprintw(w, "\b");            /* Backspace over last char */
  2026. X      wdelch(w);                /* and delete it */
  2027. X      wrefresh(w);
  2028. X      i--;
  2029. X      } else if (i < MAXLINELEN) {        /* Limit line length */
  2030. X      if (pat[i] == CTRL('u'))        /* erase line using ^u */
  2031. X      {
  2032. X          do 
  2033. X        wprintw(w, "\b"), wdelch(w) ;    /* backspace to beginning */
  2034. X          while (--i) ;
  2035. X          wrefresh(w);
  2036. X          continue ;            /* get next character */
  2037. X      }
  2038. X      if (iscntrl(pat[i]))            /* Ignore ctrl chars */
  2039. X        continue ;
  2040. X      wprintw(w, "%c", pat[i++]);
  2041. X      wrefresh(w);
  2042. X      } /* end of if */
  2043. X
  2044. X  /* By the way, we are NOT in the while loop anymore */
  2045. X
  2046. X  pat[i] = '\0';                /* Don't forget '\0'! */
  2047. X}
  2048. END_OF_FILE
  2049.   if test 3636 -ne `wc -c <'nocol-3.0/src/netmon/read_filter.c'`; then
  2050.     echo shar: \"'nocol-3.0/src/netmon/read_filter.c'\" unpacked with wrong size!
  2051.   fi
  2052.   # end of 'nocol-3.0/src/netmon/read_filter.c'
  2053. fi
  2054. if test -f 'nocol-3.0/src/perlnocol/bgpmon' -a "${1}" != "-c" ; then 
  2055.   echo shar: Will not clobber existing file \"'nocol-3.0/src/perlnocol/bgpmon'\"
  2056. else
  2057.   echo shar: Extracting \"'nocol-3.0/src/perlnocol/bgpmon'\" \(4062 characters\)
  2058.   sed "s/^X//" >'nocol-3.0/src/perlnocol/bgpmon' <<'END_OF_FILE'
  2059. X#!/usr/local/bin/perl 
  2060. X#
  2061. X# $Header: /home/aggarwal/lsrc/nocol/src/perlnocol/RCS/bgpmon,v 1.1 1993/10/30 03:59:49 aggarwal Exp $
  2062. X#
  2063. X#        bgpmon - perl monitor for BGP processes on cisco's
  2064. X#
  2065. X# Runs the command 'show ip bgp summary' on cisco routers and parses
  2066. X# the output to see if any peer is 'Idle/Active/Down' state (i.e. not
  2067. X# connected). If so, it marks the event as down. (NOTE: cisco router's
  2068. X# indicate the time that a BGP peer has been active, so its easy to
  2069. X# tell if a peer is not connected).
  2070. X#
  2071. X# Part of the NOCOL monitoring package.
  2072. X#
  2073. X# Author: Vikas Aggarwal,  vikas@jvnc.net
  2074. X#
  2075. X#     Copyright 1993 JvNCnet, Global Enterprise Services
  2076. X#
  2077. X## 
  2078. X##
  2079. X#
  2080. X#
  2081. X############################
  2082. X## Variables customization #  overrides values in the nocollib.pl library
  2083. X############################
  2084. X$rprog="rcisco";            # Path for rcisco.
  2085. X$rpasswd="";                # if NULL, uses the default in rcisco
  2086. X$rcommand="show ip bgp summary";
  2087. X$varname="BGPpeerDown";
  2088. X$varunits="State" ;            # the var.units field in EVENT struct
  2089. X$sleepint=60*10;                   # Seconds to sleep between tries.
  2090. X############################
  2091. X$debug = 0;                # set to 1 for debugging output
  2092. X$libdebug = 0;                # set to 1 for debugging output
  2093. X
  2094. Xrequire  "nocollib.pl" ;
  2095. X
  2096. X-x $rprog || die("Could not find executable $rprog, exiting");
  2097. X
  2098. X@me=split(/\//,$0); $me=pop(@me);
  2099. X#$piddir=join("/",@me); if ($piddir eq "") {$piddir=$etcdir;}
  2100. X$piddir=$etcdir;
  2101. X$cfile="$etcdir/$me-confg";
  2102. X$datafile="$datadir/$me-output";
  2103. X
  2104. X$sender= $me ;                # filled in the EVENT sender
  2105. X
  2106. X
  2107. X##
  2108. X# Read the config file. Use '\t' as a separator for 'item'
  2109. Xsub readconf {
  2110. X    open(CONFIG,"<$cfile")||die("Couldn't find $cfile, exiting");
  2111. X    while(<CONFIG>)
  2112. X    {
  2113. X    chop;
  2114. X    if(/^\s*#/) {next;}   # skip comments
  2115. X    if(/^\s*$/) {next;}   # skip blank lines
  2116. X    if (/\s*(\S+)\s+(\S+)\s*$/)
  2117. X    {
  2118. X        $item="$1\t$2" ;     # the name and address
  2119. X        push(@items,$item);
  2120. X    }
  2121. X    else {print "Ignoring illegal line: $_\n";}
  2122. X
  2123. X    }    # end while(CONFIG)
  2124. X
  2125. X    close(CONFIG);
  2126. X    if(0>$#items){die("Nothing to monitor in $cfile, exiting")};
  2127. X    if ($debug) {
  2128. X    print "Items are:\n"; foreach (@items) { print "\t$_\n" } ;
  2129. X    }
  2130. X}                # end: readconf
  2131. X
  2132. X## Check state of each router
  2133. X#
  2134. Xsub dotest {
  2135. X    local ($router) = @_ ;
  2136. X    local ($peer, $state, $peersdown);
  2137. X    local ($loginok) = 0;
  2138. X
  2139. X    if ($debug) { print "Checking $router\n"; }
  2140. X    $command="$rprog $router ".' "'."$rpasswd".'" '.'"'."$rcommand".'"';
  2141. X    if ($debug) {print "(debug) dotest: running command $command\n" ;}
  2142. X
  2143. X    open (ROUTER, "$command |") ;
  2144. X    
  2145. X    while(<ROUTER>) {
  2146. X    tr/\r\n//d;
  2147. X    if ( />/ ) {$loginok = 1 ;} # got the 'Router>' prompt
  2148. X    if ( /^\s*(\d+\.\d+.\d+.\d+).*\s+(\S+)\s*$/ )
  2149. X    {
  2150. X#        if ($debug) {print "(debug) processing line: $_\n" ;}
  2151. X        $peer = $1;
  2152. X        $state = $2;
  2153. X        if ($debug) { print "(debug): Peer= $peer, State= $state\n"; }
  2154. X        if ( $2 =~ /Active|Idle|Down/ ) { ++$peersdown ;}
  2155. X    }
  2156. X    elsif ($debug) {
  2157. X#        print "(debug) skipping line: $_\n" ;
  2158. X    }
  2159. X    }  # end while
  2160. X    close (ROUTER);
  2161. X
  2162. X    if ($loginok == 0) { 
  2163. X    print "Login into remote host failed\n" ;
  2164. X    return(-1);
  2165. X    }
  2166. X    if ($debug) {print "Peers Down= $peersdown\n" ;}
  2167. X    return ($peersdown) ;        # not caring about timeouts
  2168. X
  2169. X} # end: dotest()
  2170. X
  2171. X
  2172. X
  2173. X###
  2174. X### main
  2175. X###
  2176. X
  2177. X# Fork and get rid of old process.
  2178. Xif($p=fork){print "$p\n";exit;}
  2179. X&standalone($me,$piddir);
  2180. X
  2181. X&readconf ;
  2182. X
  2183. Xforeach $item (@items) {
  2184. X    local ($host, $addr) = split( /\t/, $item );
  2185. X    &init_event ($host, $addr, $item);
  2186. X}
  2187. X
  2188. Xwhile (1)
  2189. X{
  2190. X    local ($peersdown);
  2191. X    foreach $item (@items) {
  2192. X    local ($host, $addr) = split( /\t/, $item );
  2193. X    $peersdown = &dotest ($addr);
  2194. X        if ($linesused < 0)
  2195. X        {
  2196. X            print "$me: dotest failed for $host ($addr) , skipping\n";
  2197. X            next ;
  2198. X        }
  2199. X    if ($peersdown) {
  2200. X        &update_event($item, 0, $peersdown, $E_CRITICAL); # State DOWN
  2201. X    }
  2202. X    else {
  2203. X        &update_event($item, 1, $peersdown, $E_CRITICAL); # All OKAY
  2204. X    }
  2205. X    }
  2206. X
  2207. X    ; ## Note: we want to write the file quickly.
  2208. X
  2209. X    open(OEVENTS,">$datafile");
  2210. X    foreach $item (@items) {
  2211. X    &writeevent($item);
  2212. X    }
  2213. X    close(OEVENTS);
  2214. X    sleep($sleepint);
  2215. X}
  2216. X
  2217. END_OF_FILE
  2218.   if test 4062 -ne `wc -c <'nocol-3.0/src/perlnocol/bgpmon'`; then
  2219.     echo shar: \"'nocol-3.0/src/perlnocol/bgpmon'\" unpacked with wrong size!
  2220.   fi
  2221.   chmod +x 'nocol-3.0/src/perlnocol/bgpmon'
  2222.   # end of 'nocol-3.0/src/perlnocol/bgpmon'
  2223. fi
  2224. if test -f 'nocol-3.0/src/tpmon/tptest.c' -a "${1}" != "-c" ; then 
  2225.   echo shar: Will not clobber existing file \"'nocol-3.0/src/tpmon/tptest.c'\"
  2226. else
  2227.   echo shar: Extracting \"'nocol-3.0/src/tpmon/tptest.c'\" \(3327 characters\)
  2228.   sed "s/^X//" >'nocol-3.0/src/tpmon/tptest.c' <<'END_OF_FILE'
  2229. X/*
  2230. X * $Header: /nocol/src/tpmon/RCS/tptest.c,v 1.1 1992/06/12 21:01:19 aggarwal Exp $
  2231. X */
  2232. X
  2233. X/*
  2234. X * Thruput tester - standalone version.
  2235. X * tptest.c -- testing stub program for tpmon.c
  2236. X *
  2237. X * AUTHOR
  2238. X *    S. Spencer Sun, spencer@jvnc.net, June 1992
  2239. X *
  2240. X *
  2241. X * $Log: tptest.c,v $
  2242. X * Revision 1.1  1992/06/12  21:01:19  aggarwal
  2243. X * Initial revision
  2244. X *
  2245. X */
  2246. X/*  Copyright 1992 JvNCnet
  2247. X
  2248. X Permission to use, copy, modify and distribute this software and its
  2249. X documentation for any purpose is hereby granted without fee, provided that
  2250. X the above copyright notice appear in all copies and that both that copyright
  2251. X notice and this permission notice appear in supporting documentation, and
  2252. X that the name of JvNCnet not be used in advertising or publicity pertaining
  2253. X to distribution of the software without specific, written prior permission.
  2254. X JvNCnet makes no representations about the suitability of this software for
  2255. X any purpose.  It is provided "as is" without express or implied warranty.
  2256. X
  2257. X JvNCnet DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  2258. X IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL JvNCnet
  2259. X BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUDING DAMAGES RESULTING FROM LOSS
  2260. X OF USE, DATA OR PROFITS, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  2261. X OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  2262. X*/
  2263. X
  2264. X#include <stdio.h>
  2265. X
  2266. X#include "tptest.h"
  2267. X
  2268. Xchar *prognm;
  2269. X
  2270. Xvoid
  2271. Xusage()
  2272. X{
  2273. X  fprintf(stderr, "Usage: %s [ -b numbytes ] [ -s blocksize ] [ -t secs ]\n",
  2274. X    prognm);
  2275. X  fprintf(stderr,
  2276. X    "\t[ -p fillpattern ] [ -P port# ] [ -v ] host [ host ... ]\n\n");
  2277. X  fprintf(stderr,
  2278. X    "\tIf both -b and -t are used, then the -b part is ignored.\n");
  2279. X}
  2280. X
  2281. Xint
  2282. Xmain(argc, argv)
  2283. X  int argc;
  2284. X  char *argv[];
  2285. X{
  2286. X  extern char *optarg;
  2287. X  extern int optind;
  2288. X
  2289. X  int ch, blocksize, time, verbose;
  2290. X  long numbytes;
  2291. X  short int port;
  2292. X  char *pattern;
  2293. X  double tp;
  2294. X
  2295. X  prognm=argv[0];
  2296. X  numbytes = 0x00400000;
  2297. X  blocksize = 1024;
  2298. X  time = 0;
  2299. X  port = 9;
  2300. X  pattern = NULL;
  2301. X  verbose = 0;
  2302. X
  2303. X  while ((ch = getopt(argc, argv, "b:P:p:s:t:v")) != EOF) {
  2304. X    switch(ch) {
  2305. X      case 'b':
  2306. X        numbytes = atol(optarg);
  2307. X        if (numbytes < 0) {
  2308. X          fprintf(stderr,
  2309. X            "%s: error in numbytes parameter to -b flag, must be >= 0\n",
  2310. X            prognm);
  2311. X          return 1;
  2312. X        }
  2313. X        break;
  2314. X      case 'p':
  2315. X        pattern = optarg;
  2316. X        break;
  2317. X      case 'P':
  2318. X        port = (short int)atoi(optarg);
  2319. X        break;
  2320. X      case 's':
  2321. X        blocksize = atoi(optarg);
  2322. X        if (blocksize < 1) {
  2323. X          fprintf(stderr, "%s: blocksize parameter to -s must be non-zero\n");
  2324. X          return 1;
  2325. X        }
  2326. X      case 't':
  2327. X        time = atoi(optarg);
  2328. X        if (time < 1) {
  2329. X          fprintf(stderr, "%s: time must be at least 1 second\n", prognm);
  2330. X          return 1;
  2331. X        }
  2332. X        break;
  2333. X      case 'v':
  2334. X        verbose = 1;
  2335. X        break;
  2336. X      default:
  2337. X        usage();
  2338. X        return 1;
  2339. X        break;
  2340. X    }
  2341. X  }
  2342. X  argc -= optind;
  2343. X  if (argc < 1) {
  2344. X    fprintf(stderr, "%s: no hosts were specified\n", prognm);
  2345. X    usage();
  2346. X    return 1;
  2347. X  }
  2348. X  argv += optind;
  2349. X  do {
  2350. X    tp = throughput(*argv, port, numbytes, blocksize, pattern, time, verbose);
  2351. X    if (tp >= 0)
  2352. X      printf("Throughput for %s is %7.5g bps\n", *argv, tp);
  2353. X    ++argv;
  2354. X  } while (--argc);
  2355. X  return 0;
  2356. X}
  2357. END_OF_FILE
  2358.   if test 3327 -ne `wc -c <'nocol-3.0/src/tpmon/tptest.c'`; then
  2359.     echo shar: \"'nocol-3.0/src/tpmon/tptest.c'\" unpacked with wrong size!
  2360.   fi
  2361.   # end of 'nocol-3.0/src/tpmon/tptest.c'
  2362. fi
  2363. echo shar: End of archive 23 \(of 26\).
  2364. cp /dev/null ark23isdone
  2365. MISSING=""
  2366. 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
  2367.     if test ! -f ark${I}isdone ; then
  2368.     MISSING="${MISSING} ${I}"
  2369.     fi
  2370. done
  2371. if test "${MISSING}" = "" ; then
  2372.     echo You have unpacked all 26 archives.
  2373.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2374. else
  2375.     echo You still must unpack the following archives:
  2376.     echo "        " ${MISSING}
  2377. fi
  2378. exit 0
  2379. exit 0 # Just in case...
  2380.