Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

darkfader
Tuesday, September 30th, 2008 at 2:03:41pm MDT 

  1. #!/usr/local/bin/ksh93
  2. # Copyright Florian Heigl(2008)
  3. # availability / other licences upon request. i refuse to think about it now.
  4. # no warranties.
  5.  
  6.  
  7. # Syntax to be
  8. # nagswitch -n <switch name> -g <hostgroup name> [-i <switch ip address] [-c "Description String"]
  9.  
  10.  
  11. # Variables
  12. naghostname=""
  13. # ex: naghostname="vendor-model-num"   
  14. # mandatory: switch hostname as used by nagios
  15. #
  16. naghostname_ip=""
  17. # ex: naghostname_ip="192.168.0.1"     
  18. # mandatory: alternate ip for accessing the switch in case the nagios hostname
  19. # is not resolvable or the visible hostname isnt routable etc.
  20. # obviously this should be optional
  21. # IPv6 addresses should work just as fine
  22. #
  23. naghostgrp=""
  24. # ex: naghostgrp="lanswitches"
  25. # mandatory: nagios hostgroup the device should be added to, must be predefined
  26. # it would be possible, but not helpful to use something like "default" for
  27. # small environments (i guess)
  28. #
  29. #numports=16            # number of switchports
  30. # obsolete, removed,
  31. # will be enumerated via snmp, unless specified
  32. # there are a few pieces that would not work with the switch being unreachable
  33. # needs to some consideration
  34. # also it seems some switches allow for per-vlan statistics and other stuff
  35. # that will be shown as interfaces and need to be filtered, probably via
  36. # iftype (dealt with, as long as the interface types are ethernet-ish
  37. #
  38.  
  39.  
  40. #naghostname="msu1800-1"       
  41. #naghostname_ip="192.168.10.35
  42. #nagdescr="Nortel Metro Ethernet Services Unit 1800"
  43. #naghostgroup=switches
  44.  
  45.  
  46. #naghostname="lcs-gs9420-1"
  47. #naghostname_ip="192.168.10.36"
  48. #nagdescr="Longshine GS9420"
  49. #naghostgroup="switches"
  50.  
  51. #naghostname="linksys"
  52. #naghostname_ip="192.168.10.17"
  53. #nagdescr="Linksys WRT54GL DDWRT"
  54. #naghostgroup="routers"
  55.  
  56.  
  57. SNMPCMD="snmpget -c public -v 1"
  58. SNMPWCMD="snmpwalk -c public -v 1"
  59.  
  60.  
  61. # exit if our needed vars are unset, especially now that i can't supply them
  62. # via cmd line
  63.  
  64. if [ -z $naghostname ] || [ -z naghostname_ip ]
  65. then
  66.     echo "Please supply needed information, see source."
  67. fi
  68.  
  69. # define a description string if not already set
  70. if [ -z $nagdescr ]
  71. then
  72.     nagdescr=$( $SNMPCMD $naghostname SNMPv2-MIB::sysName.0 | cut -f3 -d\: )
  73. fi
  74.  
  75.  
  76. # start writing info to cfg file
  77.  
  78. # start out by host definition, use host/service templates
  79. echo "define host{
  80.         use             generic-switch
  81.         host_name       $naghostname
  82.         alias           $nagdescr
  83.         address         $naghostname_ip
  84.         hostgroups      switches
  85.         }" > $naghostname.cfg
  86.  
  87.  
  88. # set up generic services (ping, uptime)
  89. echo "define service{
  90.         use               generic-service
  91.         host_name              $naghostname
  92.         service_description     PING
  93.         service_description     PING
  94.         check_command           check_ping!200.0,20%!600.0,60%
  95.         normal_check_interval   5
  96.         retry_check_interval    1
  97. }" >> $naghostname.cfg
  98.  
  99. #set up specific services (ssh, http[s], telnet, snmp)
  100.  
  101.  
  102.  
  103. # set up services for each port (link state, bandwidth)
  104. # to be added:
  105. # these will all be needed to make this script actually useful, as in
  106. # reducing false positives
  107. # * error counters
  108. # * full duplex / autoneg (must be adjustable to full-duplex manual for
  109. #   people still living in '90s, UNLESS gigabit link)
  110. # * bandwidth monitoring right now uses random values for fast ethernet,
  111. #   need to find a query link speed to get those right
  112. # * also, need to set up according to admin/oper states:
  113. #   op down at scan:    no notifications
  114. #   admin down at scan: no active checks
  115.  
  116. # id of switchport padded with two zeroes, not yet according to port number
  117. # this isnt real padding, obviously. wc -c on number of ports should
  118. # do though, but i.e. vlan ports (1026++ on my switch) should be excluded
  119.  
  120. typeset -Z02 idpad
  121.  
  122. for id in $( $SNMPWCMD $naghostname_ip IF-MIB::ifIndex | awk '{print $NF}' )
  123.  
  124. do
  125.  
  126. ifType="$( $SNMPCMD $naghostname_ip IF-MIB::ifType.$id | awk '{print $NF}' | cut -f1 -d\( )"
  127. if [ "X${ifType}" = "XethernetCsmacd" ] || [ "X${ifType}" = "XgigabitEthernet" ]
  128.  
  129. then
  130.  
  131. idpad="$id"
  132.  
  133. # i wonder if anyone work prefer the ifName supplied names (1/10...)
  134. # geeks probably yes, monitoring people probably not.
  135. #
  136. echo "define service{
  137.         use                     generic-service
  138.         host_name               $naghostname
  139.         service_description     Port $idpad Link Status
  140.         check_command           check_snmp!-C public -o ifOperStatus.$id -r 1 -m RFC1213-MIB
  141.         }
  142. define service{
  143.         use                     generic-service
  144.         host_name               $naghostname
  145.         service_description     Port $idpad Bandwidth Usage
  146.         check_command           check_local_mrtgtraf!/usr/local/www/mrtg/${naghostname_ip}_${id}.log!AVG!1000000,1000000!5000000,5000000!10
  147.         }
  148. define servicedependency{
  149.         host_name                     $naghostname
  150.         service_description          Port $idpad Link Status
  151.         dependent_host_name          $naghostname
  152.         dependent_service_description   Port $idpad Bandwidth Usage
  153.         execution_failure_criteria      w,c,u
  154.         notification_failure_criteria   w,c,u
  155.         }" >> $naghostname.cfg
  156.  
  157. if [ $id = 1 ]
  158.  then
  159.    all_port_services="Port $idpad Link Status, Port $idpad Bandwidth Usage"
  160.  else
  161.    all_port_services="${all_port_services},Port $idpad Link Status, Port $idpad Bandwidth Usage"
  162. fi
  163.  
  164. fi
  165.  
  166.  
  167. done
  168. echo "define servicedependency{
  169.         host_name                       $naghostname
  170.         service_description             PING
  171.         dependent_host_name             $naghostname
  172.         dependent_service_description   $all_port_services
  173.         execution_failure_criteria      w,c,u
  174.         notification_failure_criteria   w,c,u
  175. }" >> $naghostname.cfg

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

fantasy-obligation