cloudstack-nagios 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cloudstack-nagios (0.1.3)
4
+ cloudstack-nagios (0.2.0)
5
5
  erubis (~> 2.7.0)
6
6
  highline (~> 1.6.20)
7
7
  sshkit (~> 1.1.0)
data/README.md CHANGED
@@ -3,6 +3,13 @@
3
3
  Cloudstack Nagios helps you monitoring your Cloudstack environment with Nagios.
4
4
  Cloudstack Nagios uses the Cloudsdtack API to collect information about system vm's and cloudstack ressources.
5
5
 
6
+ ## Prerequisites
7
+
8
+ * Cloudstack Root Admin keys must be used.
9
+ * In order to connect to system vms the private ssh key found on the Cloudstack management server under /var/lib/cloud/management/.ssh/id_rsa must be used.
10
+ * The system vms must be reachable over SSH (default port 3922) from the nagios server executing the checks.
11
+ * check with 'ssh -i /var/lib/cloud/management/.ssh/id_rsa -p 3922 <router_mgmt_ip>'
12
+
6
13
  ## Installation
7
14
 
8
15
  Install the cloudstack-cli gem:
@@ -32,18 +39,45 @@ Example content of the configuration file:
32
39
 
33
40
  ## Usage
34
41
 
42
+ ### Basics
43
+
35
44
  See the help screen:
36
45
 
37
46
  $ cs-nagios
38
47
 
39
- Generate nagios host and services configuration for virtual routers:
48
+ ### Generate Nagios configuration files
49
+
50
+ Generate nagios host configuration for virtual routers:
51
+
52
+ $ cs-nagios nagios_config host
53
+
54
+ Generate nagios host configuration for virtual routers:
55
+
56
+ $ cs-nagios nagios_config service
40
57
 
41
- $ cs-nagios config
58
+ Note that you can also use your own ERB templates using the '--template' option to generate the nagios confifuration files.
59
+
60
+ ### Check system vms over ssh
61
+
62
+ The following checks are available:
63
+
64
+ * memory - measure memory usage in percents
65
+ * cpu - measure cpu usage in percent
66
+ * network - measure network usage
67
+ * rootfs_rw - check if the root file system is writeable
68
+
69
+ ### Enabling snmpd checks
70
+
71
+ If you want to check your system vms with standard snmp checks instead of checking over SSH, there are commands to configure snmpd on the machines and open the firewall.
72
+
73
+ * snmpd_config enable - goes to all the routers and configure snmpd
74
+ * snmpd_config check - test if port TCP 161 is reachable on routers
75
+
76
+ Note: If you want to use snmp checks, you have to adapt the nagios configuration files accordingly.
42
77
 
43
78
  ## References
44
79
  - [Cloudstack API documentation](http://cloudstack.apache.org/docs/api/apidocs-4.2/TOC_Root_Admin.html)
45
80
 
46
-
47
81
  ## Contributing
48
82
 
49
83
  1. Fork it
@@ -65,10 +65,10 @@ module CloudstackNagios
65
65
  objects.select {|r| r[tag_name].downcase == tag.downcase}
66
66
  end
67
67
 
68
- def sshoptions
68
+ def sshoptions(ssh_key)
69
69
  {
70
70
  timeout: 5,
71
- keys: %w(/var/lib/cloud/management/.ssh/id_rsa),
71
+ keys: [ssh_key],
72
72
  auth_methods: %w(publickey)
73
73
  }
74
74
  end
@@ -85,7 +85,7 @@ module CloudstackNagios
85
85
  require command
86
86
  end
87
87
 
88
- desc ":nagios_config SUBCOMMAND ...ARGS", "Nagios configuration commands"
88
+ desc "nagios_config SUBCOMMAND ...ARGS", "Nagios configuration commands"
89
89
  subcommand :nagios_config, NagiosConfig
90
90
 
91
91
  desc "snmpd_config SUBCOMMAND ...ARGS", "snmpd configuration commands"
@@ -4,7 +4,7 @@ class Check < CloudstackNagios::Base
4
4
 
5
5
  RETURN_CODES = {0 => 'ok', 1 => 'warning', 2 => 'critical'}
6
6
 
7
- desc "check memory HOST", "check memory on host"
7
+ desc "memory HOST", "check memory on host"
8
8
  option :host,
9
9
  desc: 'hostname or ipaddress',
10
10
  required: true,
@@ -19,10 +19,18 @@ class Check < CloudstackNagios::Base
19
19
  type: :numeric,
20
20
  default: 95,
21
21
  aliases: '-c'
22
+ option :ssh_key,
23
+ desc: 'ssh private key to use',
24
+ default: '/var/lib/cloud/management/.ssh/id_rsa'
25
+ option :port,
26
+ desc: 'ssh port to use',
27
+ type: :numeric,
28
+ default: 3922,
29
+ aliases: '-p'
22
30
  def memory
23
31
  host = SSHKit::Host.new("root@#{options[:host]}")
24
- host.ssh_options = sshoptions
25
- host.port = 3922
32
+ host.ssh_options = sshoptions(options[:ssh_key])
33
+ host.port = options[:port]
26
34
  free_output = ""
27
35
  on host do |h|
28
36
  free_output = capture(:free)
@@ -36,7 +44,7 @@ class Check < CloudstackNagios::Base
36
44
  exit data[0]
37
45
  end
38
46
 
39
- desc "check cpu", "check memory on host"
47
+ desc "cpu", "check memory on host"
40
48
  option :host,
41
49
  desc: 'hostname or ipaddress',
42
50
  required: true,
@@ -49,10 +57,18 @@ class Check < CloudstackNagios::Base
49
57
  desc: 'critical level',
50
58
  type: :numeric,
51
59
  default: 95
60
+ option :ssh_key,
61
+ desc: 'ssh private key to use',
62
+ default: '/var/lib/cloud/management/.ssh/id_rsa'
63
+ option :port,
64
+ desc: 'ssh port to use',
65
+ type: :numeric,
66
+ default: 3922,
67
+ aliases: '-p'
52
68
  def cpu(host)
53
69
  host = SSHKit::Host.new("root@#{options[:host]}")
54
- host.ssh_options = sshoptions
55
- host.port = 3922
70
+ host.ssh_options = sshoptions(options[:ssh_key])
71
+ host.port = options[:port]
56
72
  mpstat_output = ""
57
73
  on host do |h|
58
74
  mpstat_output = capture(:mpstat)
@@ -64,7 +80,7 @@ class Check < CloudstackNagios::Base
64
80
  exit data[0]
65
81
  end
66
82
 
67
- desc "check rootfs_rw", "check if the rootfs is read/writeable on host"
83
+ desc "rootfs_rw", "check if the rootfs is read/writeable on host"
68
84
  option :host,
69
85
  desc: 'hostname or ipaddress',
70
86
  required: true,
@@ -79,21 +95,29 @@ class Check < CloudstackNagios::Base
79
95
  type: :numeric,
80
96
  default: 95,
81
97
  aliases: '-c'
98
+ option :ssh_key,
99
+ desc: 'ssh private key to use',
100
+ default: '/var/lib/cloud/management/.ssh/id_rsa'
101
+ option :port,
102
+ desc: 'ssh port to use',
103
+ type: :numeric,
104
+ default: 3922,
105
+ aliases: '-p'
82
106
  def rootfs_rw
83
107
  host = SSHKit::Host.new("root@#{options[:host]}")
84
- host.ssh_options = sshoptions
85
- host.port = 3922
86
- mpstat_output = ""
108
+ host.ssh_options = sshoptions(options[:ssh_key])
109
+ host.port = options[:port]
110
+ proc_out = ""
87
111
  on host do |h|
88
112
  proc_out = capture(:cat, '/proc/mounts')
89
113
  end
90
114
  rootfs_rw = proc_out.match(/rootfs\srw\s/)
91
- data = check_data(100, usage, options[:warning], options[:critical])
92
- puts "ROOTFS_RW #{rootfs_rw ? 'OK - root fs writeable' : 'CRITICAL - rootfs not writeable'}"
93
- exit data[0]
115
+ status = rootfs_rw ? 0 : 2
116
+ puts "ROOTFS_RW #{rootfs_rw ? 'OK - rootfs writeable' : 'CRITICAL - rootfs NOT writeable'}"
117
+ exit status
94
118
  end
95
119
 
96
- desc "check network", "check network usage on host"
120
+ desc "network", "check network usage on host"
97
121
  option :host,
98
122
  desc: 'hostname or ipaddress',
99
123
  required: true,
@@ -108,10 +132,18 @@ class Check < CloudstackNagios::Base
108
132
  type: :numeric,
109
133
  default: 95,
110
134
  aliases: '-c'
135
+ option :ssh_key,
136
+ desc: 'ssh private key to use',
137
+ default: '/var/lib/cloud/management/.ssh/id_rsa'
138
+ option :port,
139
+ desc: 'ssh port to use',
140
+ type: :numeric,
141
+ default: 3922,
142
+ aliases: '-p'
111
143
  def network
112
144
  host = SSHKit::Host.new("root@#{options[:host]}")
113
- host.ssh_options = sshoptions
114
- host.port = 3922
145
+ host.ssh_options = sshoptions(options[:ssh_key])
146
+ host.port = options[:port]
115
147
  r1, t1, r2, t2 = ""
116
148
  on host do |h|
117
149
  r1 = capture(:cat, '/sys/class/net/eth0/statistics/rx_bytes').to_f
@@ -1,13 +1,23 @@
1
1
  class NagiosConfig < CloudstackNagios::Base
2
2
 
3
- desc "nagios_config hosts", "generate nagios hosts configuration for virtual routers"
3
+ desc "hosts", "generate nagios hosts configuration for virtual routers"
4
+ option :template,
5
+ desc: "path of ERB template to use",
6
+ default: File.join(File.dirname(__FILE__), '..', 'templates', 'cloudstack_routers_hosts.cfg.erb'),
7
+ aliases: '-t'
4
8
  def hosts
5
- puts load_template("cloudstack_routers_hosts.cfg.erb").result(routers: routers)
9
+ host_template = load_template(options[:template])
10
+ puts host_template.result(routers: cs_routers)
6
11
  end
7
12
 
8
- desc "nagios_config services", "generate nagios services configuration for virtual routers"
13
+ desc "services", "generate nagios services configuration for virtual routers"
14
+ option :template,
15
+ desc: "path of ERB template to use",
16
+ default: File.join(File.dirname(__FILE__), '..', 'templates', 'cloudstack_routers_services.cfg.erb'),
17
+ aliases: '-t'
9
18
  def services
10
- puts load_template("cloudstack_routers_services.cfg.erb").result(routers: routers)
19
+ service_template = load_template(options[:template])
20
+ puts service_template.result(routers: cs_routers)
11
21
  end
12
22
 
13
23
  end
@@ -4,11 +4,11 @@ require 'timeout'
4
4
 
5
5
  class SnmpdConfig < CloudstackNagios::Base
6
6
 
7
- desc "snmpd_config check [vms]", "check if snmpd is configured on virtual routers"
7
+ desc "check [vms]", "check if snmpd is configured on virtual routers"
8
8
  def check(*vms)
9
9
  if vms.size == 0
10
10
  say 'Get a list of all routers from cloudstack..', :yellow
11
- vms = router_ips(routers)
11
+ vms = router_ips
12
12
  end
13
13
  vms.each do |host|
14
14
  begin
@@ -23,20 +23,28 @@ class SnmpdConfig < CloudstackNagios::Base
23
23
  end
24
24
  end
25
25
 
26
- desc "snmpd_config enable [vms]", "enable snmpd configuration on virtual routers"
26
+ desc "enable [vms]", "enable snmpd configuration on virtual routers"
27
27
  option :apt,
28
28
  desc: 'use apt-get to install snmpd packages',
29
29
  type: :boolean
30
+ option :ssh_key,
31
+ desc: 'ssh private key to use',
32
+ default: '/var/lib/cloud/management/.ssh/id_rsa'
33
+ option :port,
34
+ desc: 'ssh port to use',
35
+ type: :numeric,
36
+ default: 3922,
37
+ aliases: '-p'
30
38
  def enable(*vms)
31
39
  apt = options[:apt]
32
40
  if vms.size == 0
33
- say 'Get a list of all routers from cloudstack..', :yellow
41
+ say 'Get a list of all routers from Cloudstack..', :yellow
34
42
  vms = router_ips
35
43
  end
36
44
  hosts = vms.map do |router|
37
45
  host = SSHKit::Host.new("root@#{router}")
38
- host.ssh_options = sshoptions
39
- host.port = 3922
46
+ host.ssh_options = sshoptions(options[:ssh_key])
47
+ host.port = options[:port]
40
48
  host
41
49
  end
42
50
  say 'Connect to router and enable snmpd...', :yellow
@@ -57,7 +65,7 @@ class SnmpdConfig < CloudstackNagios::Base
57
65
 
58
66
  no_commands do
59
67
 
60
- def router_ips(vrs = routers)
68
+ def router_ips(vrs = cs_routers)
61
69
  ips = []
62
70
  vrs.each do |router|
63
71
  ips << router['linklocalip'] unless router['linklocalip'] == nil
@@ -1,13 +1,18 @@
1
1
  module CloudstackNagios
2
2
  module Helper
3
- def load_template(name)
4
- templ = File.read(File.join(File.dirname(__FILE__), "templates", name))
5
- Erubis::Eruby.new(templ)
3
+ def load_template(template_path)
4
+ if File.file?(template_path)
5
+ templ = File.read(template_path)
6
+ return Erubis::Eruby.new(templ)
7
+ else
8
+ say "Error: template not found #{template_path}"
9
+ exit 1
10
+ end
6
11
  end
7
12
 
8
- def routers
9
- routers = client.list_routers
10
- routers += client.list_routers(projectid: -1)
13
+ def cs_routers
14
+ routers = client.list_routers(status: 'Running')
15
+ routers += client.list_routers(projectid: -1, status: 'Running')
11
16
  end
12
17
  end
13
18
  end
@@ -1,3 +1,3 @@
1
1
  module CloudstackNagios
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudstack-nagios
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: