Skip to content

Instantly share code, notes, and snippets.

@peelman
Last active April 14, 2020 20:03
Show Gist options
  • Save peelman/ef7b682de3af579c2896585385e18e7c to your computer and use it in GitHub Desktop.
Save peelman/ef7b682de3af579c2896585385e18e7c to your computer and use it in GitHub Desktop.
check_juniper_ex_virtchas_count.rb

Check count of members in a Juniper virtual chassis

#!/usr/bin/ruby
######################################################################################################
#
# Description:
# Query an Virtual Chassis and check how many switches exist in it
#
######################################################################################################
#
# Author: Nick Peelman (2017-02-15)
#
######################################################################################################
#
# Usage:
# check_juniper_ex_virtchas_count.rb -H <hostname> -C <community> -c <expected_count>
#
# Parameters:
# * <hostname>: the hostname / IP Address of the virtual chassis
# * <community>: the SNMP community string
# * <expected_count>: how many switches should be in the stack
#
######################################################################################################
#
# Requirements
# * gem install snmp
#
######################################################################################################
require 'snmp'
require 'optparse'
######################################################################################################
OID_CHASSIS_SERIALS = "1.3.6.1.4.1.2636.3.40.1.4.1.1.1.2"
######################################################################################################
@hostname = nil
@community = nil
@expected_count = 0
def parse_args(args = {})
@opts = OptionParser.new
@opts.on('-H', "--host HOSTNAME", "Hostname of the Virtual Chassis") do |hostname|
@hostname = hostname
end
@opts.on("-C", "--community COMMUNITY", "SNMP Community String") do |community|
@community = community
end
@opts.on("-c", "--count COUNT", "The number of switches that should exist") do |count|
@expected_count = count
end
@opts.on_tail("-h", "--help", "Show this message") do
puts @opts
exit
end
@opts.parse!
end
def members(host, community)
members = []
SNMP::Manager.open(host: host, community: community) do |manager|
manager.walk([OID_CHASSIS_SERIALS]) { |var|
members.push var.first.value
}
end
return members
end
parse_args()
chassis = members(@hostname, @community)
case
when chassis.count == @expected_count
puts "OK: Chassis Count is #{chassis.count}"
exit 0
when chassis.count < @expected_count
puts "CRITICAL: The chassis count (#{chassis.count}) is too low!"
exit 2
when chassis.count > @expected_count
puts "WARNING: The chassis count (#{chassis.count}) is too high!"
exit 1
else
puts "UNKNOWN: Could not determine chassis count (reporting: #{chassis.count})"
exit 3
end
@vikaskute12
Copy link

Do u have any information on how to monitor interfaces in the stack members..

@peelman
Copy link
Author

peelman commented Apr 14, 2020

I'd just use the standard monitoring_plugins interface monitor. As long as you're monitoring a shared IP interface, you'll be able to see the info for all interfaces in the stack.

If you're large enough to run a stack of these things though, and even if you just have > 1 of them, I highly suggest LibreNMS. Will give you a lot more than just up/down status.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment