Class: SnmpdConfig
- Inherits:
-
CloudstackNagios::Base
- Object
- Thor
- CloudstackNagios::Base
- SnmpdConfig
- Defined in:
- lib/cloudstack-nagios/commands/snmpd_config.rb
Constant Summary
Constants included from CloudstackNagios::Helper
CloudstackNagios::Helper::RETURN_CODES
Instance Attribute Summary
Attributes inherited from CloudstackNagios::Base
Instance Method Summary collapse
Methods inherited from CloudstackNagios::Base
Methods included from CloudstackNagios::Helper
#check_data, #cs_routers, #exit_with_failure, #load_template, #storage_pools
Instance Method Details
#check(*vms) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/cloudstack-nagios/commands/snmpd_config.rb', line 8 def check(*vms) if vms.size == 0 say 'Get a list of all routers from cloudstack..', :yellow vms = router_ips end vms.each do |host| begin Timeout::timeout(1) do socket = TCPSocket.new(host, "161") socket.close puts "port is open on host #{host}" end rescue => e puts "port is closed on host #{host}" end end end |
#enable(*vms) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/cloudstack-nagios/commands/snmpd_config.rb', line 38 def enable(*vms) apt = [:apt] if vms.size == 0 say 'Get a list of all routers from Cloudstack..', :yellow vms = router_ips end hosts = vms.map do |router| host = SSHKit::Host.new("root@#{router}") host. = ([:ssh_key]) host.port = [:ssh_port] host end say 'Connect to router and enable snmpd...', :yellow on hosts, in: :sequence, wait: 10 do begin execute 'apt-get', 'update' execute 'apt-get', '-y', 'install', 'snmpd' upload! File.join(File.dirname(__FILE__), '..', 'files', 'snmpd.conf'), '/etc/snmp/snmpd.conf' execute 'service', 'snmpd', 'restart' execute 'iptables', '-A INPUT -p tcp -m tcp --dport 161 -j ACCEPT' rescue StandardError => e puts 'configuration failed!' puts e. puts e.backtrace end end end |