class SnmpdConfig

Public Instance Methods

check(*vms) click to toggle source
   # File lib/cloudstack-nagios/commands/snmpd_config.rb
 9 def check(*vms)
10   if vms.size == 0
11     say 'Get a list of all routers from cloudstack..', :yellow
12     vms = router_ips
13   end
14   vms.each do |host|
15     begin
16       Timeout::timeout(1) do
17         socket = TCPSocket.new(host, "161")
18         socket.close
19         puts "port is open on host #{host}"
20       end
21     rescue => e
22       puts "port is closed on host #{host}"
23     end
24   end
25 end
enable(*vms) click to toggle source
   # File lib/cloudstack-nagios/commands/snmpd_config.rb
39 def enable(*vms)
40   apt = options[:apt]
41   if vms.size == 0
42     say 'Get a list of all routers from Cloudstack..', :yellow
43     vms = router_ips
44   end
45   hosts = vms.map do |router|
46     host = SSHKit::Host.new("root@#{router}")
47     host.ssh_options = sshoptions(options[:ssh_key])
48     host.port = options[:ssh_port]
49     host
50   end
51   say 'Connect to router and enable snmpd...', :yellow
52   on hosts, in: :sequence, wait: 10 do
53     begin
54       execute 'apt-get', 'update'
55       execute 'apt-get', '-y', 'install', 'snmpd'
56       upload! File.join(File.dirname(__FILE__), '..', 'files', 'snmpd.conf'), '/etc/snmp/snmpd.conf'
57       execute 'service', 'snmpd', 'restart'
58       execute 'iptables', '-A INPUT -p tcp -m tcp --dport 161 -j ACCEPT'
59     rescue StandardError => e
60       puts 'configuration failed!'
61       puts e.message
62       puts e.backtrace
63     end
64   end
65 end
router_ips(vrs = cs_routers) click to toggle source
   # File lib/cloudstack-nagios/commands/snmpd_config.rb
69 def router_ips(vrs = cs_routers)
70   ips = []
71   vrs.each do |router|
72     ips << router['linklocalip'] unless router['linklocalip'] == nil
73   end
74   ips
75 end