gnms 2.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of gnms might be problematic. Click here for more details.
- data/LICENSE +459 -0
- data/README +29 -0
- data/bin/gnms +11 -0
- data/gnms.gemspec +70 -0
- data/lib/cmd_parse.rb +747 -0
- data/lib/config_global.rb +414 -0
- data/lib/contact.rb +171 -0
- data/lib/external/crypt/blowfish-tables.rb +190 -0
- data/lib/external/crypt/blowfish.rb +110 -0
- data/lib/external/crypt/cbc.rb +123 -0
- data/lib/external/crypt/stringxor.rb +27 -0
- data/lib/external/fog.rb +41 -0
- data/lib/external/jjmx.rb +45 -0
- data/lib/external/sms.rb +282 -0
- data/lib/external/xmpp4r-simple.rb +497 -0
- data/lib/format.rb +85 -0
- data/lib/gnms.rb +329 -0
- data/lib/gui/about_window.rb +177 -0
- data/lib/gui/adddelnode.rb +799 -0
- data/lib/gui/base_window.rb +789 -0
- data/lib/gui/canvas_map.rb +498 -0
- data/lib/gui/charts/gruff.rb +51 -0
- data/lib/gui/color_macro.rb +145 -0
- data/lib/gui/config_window.rb +2151 -0
- data/lib/gui/custom_plugin_window.rb +90 -0
- data/lib/gui/debug_window.rb +46 -0
- data/lib/gui/event_window.rb +469 -0
- data/lib/gui/find_node_window.rb +438 -0
- data/lib/gui/help_window.rb +47 -0
- data/lib/gui/ipcalculator.rb +147 -0
- data/lib/gui/jmx_ref_window.rb +309 -0
- data/lib/gui/link_view.rb +46 -0
- data/lib/gui/mib_browser.rb +585 -0
- data/lib/gui/node_host_property.rb +3712 -0
- data/lib/gui/node_host_view.rb +270 -0
- data/lib/gui/node_network_property.rb +1059 -0
- data/lib/gui/node_network_view.rb +186 -0
- data/lib/gui/node_view.rb +672 -0
- data/lib/gui/oid_ref_window.rb +288 -0
- data/lib/gui/snmptrap_ref_window.rb +288 -0
- data/lib/gui/sub/account_frame.rb +196 -0
- data/lib/gui/sub/contact_frame.rb +519 -0
- data/lib/gui/syslog_ref_window.rb +288 -0
- data/lib/gui/treenode_window.rb +320 -0
- data/lib/gui/update_window.rb +124 -0
- data/lib/gui/widgets.rb +169 -0
- data/lib/gui/wmi_ref_window.rb +286 -0
- data/lib/interface.rb +16 -0
- data/lib/ipcalc.rb +266 -0
- data/lib/link.rb +45 -0
- data/lib/main.rb +1091 -0
- data/lib/monitor/client/custom/custom_monitoring.rb +40 -0
- data/lib/monitor/client/jmx/jmx_attr_monitoring.rb +36 -0
- data/lib/monitor/client/jmx/jmx_monitoring.rb +83 -0
- data/lib/monitor/client/jmx/jmx_ref.rb +114 -0
- data/lib/monitor/client/snmp/mibs/SNMPv2-MIB.txt +854 -0
- data/lib/monitor/client/snmp/mibs/SNMPv2-SMI.txt +344 -0
- data/lib/monitor/client/snmp/oid_ref.rb +141 -0
- data/lib/monitor/client/snmp/snmp.rb +178 -0
- data/lib/monitor/client/snmp/snmp_monitoring.rb +58 -0
- data/lib/monitor/client/wmi/wmi.rb +139 -0
- data/lib/monitor/client/wmi/wmi_monitoring.rb +60 -0
- data/lib/monitor/client/wmi/wmi_ref.rb +141 -0
- data/lib/monitor/custom_plugin.rb +50 -0
- data/lib/monitor/server/msg_buffer.rb +39 -0
- data/lib/monitor/server/snmp/snmptrap_analyzer.rb +81 -0
- data/lib/monitor/server/snmp/snmptrap_capture.rb +26 -0
- data/lib/monitor/server/snmp/snmptrap_monitoring.rb +32 -0
- data/lib/monitor/server/snmp/snmptrap_ref.rb +135 -0
- data/lib/monitor/server/snmp/snmptrap_server.rb +50 -0
- data/lib/monitor/server/syslog/syslog_analyzer.rb +141 -0
- data/lib/monitor/server/syslog/syslog_capture.rb +28 -0
- data/lib/monitor/server/syslog/syslog_monitoring.rb +32 -0
- data/lib/monitor/server/syslog/syslog_ref.rb +136 -0
- data/lib/monitor/server/syslog/syslog_server.rb +43 -0
- data/lib/node.rb +1020 -0
- data/lib/node_db.rb +2668 -0
- data/lib/node_host.rb +215 -0
- data/lib/node_listener.rb +639 -0
- data/lib/node_network.rb +269 -0
- data/lib/node_property.rb +39 -0
- data/lib/notify/alarm.rb +247 -0
- data/lib/notify/irc_bot.rb +167 -0
- data/lib/notify/xmpp_bot.rb +107 -0
- data/lib/service.rb +36 -0
- data/lib/version.rb +8 -0
- data/pixmap/bg/map_bg.jpg +0 -0
- data/pixmap/bg/map_bg2.jpg +0 -0
- data/pixmap/logo.jpg +0 -0
- data/pixmap/logo_icon.png +0 -0
- data/pixmap/os/3com.png +0 -0
- data/pixmap/os/aix.gif +0 -0
- data/pixmap/os/amiga.png +0 -0
- data/pixmap/os/beos.png +0 -0
- data/pixmap/os/cisco.png +0 -0
- data/pixmap/os/freebsd.png +0 -0
- data/pixmap/os/hp.png +0 -0
- data/pixmap/os/hurd.gif +0 -0
- data/pixmap/os/irix.gif +0 -0
- data/pixmap/os/linux.png +0 -0
- data/pixmap/os/mac.png +0 -0
- data/pixmap/os/netbsd.gif +0 -0
- data/pixmap/os/netware.png +0 -0
- data/pixmap/os/openbsd.png +0 -0
- data/pixmap/os/os2warp.gif +0 -0
- data/pixmap/os/qnx.gif +0 -0
- data/pixmap/os/sco.gif +0 -0
- data/pixmap/os/sgi.xpm +111 -0
- data/pixmap/os/solaris.gif +0 -0
- data/pixmap/os/unix.gif +0 -0
- data/pixmap/os/unknown.png +0 -0
- data/pixmap/os/vms.xpm +345 -0
- data/pixmap/os/windows.png +0 -0
- data/pixmap/type/cloud.png +0 -0
- data/pixmap/type/device.png +0 -0
- data/pixmap/type/firewall.png +0 -0
- data/pixmap/type/gateway.png +0 -0
- data/pixmap/type/home.png +0 -0
- data/pixmap/type/host.png +0 -0
- data/pixmap/type/network.png +0 -0
- data/pixmap/type/printer.png +0 -0
- data/pixmap/type/router.png +0 -0
- data/pixmap/type/server.png +0 -0
- data/pixmap/type/switch.png +0 -0
- data/pixmap/type/vm.png +0 -0
- data/plugins/Defaultme.rb +7 -0
- data/plugins/DnsCheck.rb +46 -0
- data/plugins/FooMonitor.rb +26 -0
- data/plugins/HttpVirtualHostMonitor.rb +43 -0
- data/plugins/MysqlShowStatusMonitor.rb +64 -0
- data/plugins/PgsqlPercentConnectionMonitor.rb +72 -0
- data/plugins/SshCpuLoadMonitor.rb +85 -0
- data/plugins/SshDiskMonitor.rb +69 -0
- data/plugins/SshFgtAvExpiredMonitor.rb +75 -0
- data/plugins/SshPercentUsedRamMonitor.rb +74 -0
- data/plugins/TelnetCpuLoadMonitor.rb +69 -0
- data/plugins/example1.rb +15 -0
- data/plugins/example2.rb +7 -0
- data/sound/beep.wav +0 -0
- metadata +378 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
require "#{GNMSLIB}"+'/monitor/custom_plugin'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'net/http'
|
5
|
+
require 'uri'
|
6
|
+
rescue LoadError
|
7
|
+
$log.fatal("HttpVirtualHostMonitor: you need to install http library for ruby")
|
8
|
+
end
|
9
|
+
|
10
|
+
class HttpVirtualHostMonitor < CustomPlugin
|
11
|
+
#declare static methods
|
12
|
+
def HttpVirtualHostMonitor::description()
|
13
|
+
return "Check HTTP Virtual Hosts using HTTP GET request"
|
14
|
+
end
|
15
|
+
def HttpVirtualHostMonitor::name()
|
16
|
+
return "Check HTTP Virtual Hosts"
|
17
|
+
end
|
18
|
+
def HttpVirtualHostMonitor::parameter()
|
19
|
+
return "http://www.google.com"
|
20
|
+
end
|
21
|
+
def HttpVirtualHostMonitor::default_severity()
|
22
|
+
return "MAJOR"
|
23
|
+
end
|
24
|
+
|
25
|
+
def monitor()
|
26
|
+
host=get_node().ip
|
27
|
+
domain = HttpVirtualHostMonitor::parameter()
|
28
|
+
|
29
|
+
begin
|
30
|
+
uri = URI("#{domain}")
|
31
|
+
res = Net::HTTP.get_response(uri)
|
32
|
+
case res
|
33
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
34
|
+
set_state("NORMAL")
|
35
|
+
else
|
36
|
+
set_state("CRITICAL","Virtual Hosts is not responding, HTTP code #{res.code}")
|
37
|
+
end
|
38
|
+
rescue
|
39
|
+
$log.error("Virtual Hosts plugin #{host}")
|
40
|
+
set_state("UNKNOWN")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require "#{GNMSLIB}"+'/monitor/custom_plugin'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'mysql'
|
5
|
+
rescue LoadError
|
6
|
+
$log.fatal("MysqlShowStatusMonitor: you need to install mysql library for ruby")
|
7
|
+
$mysql_lib_error=false
|
8
|
+
raise LoadError
|
9
|
+
end
|
10
|
+
|
11
|
+
class MysqlShowStatusMonitor < CustomPlugin
|
12
|
+
#declare static methods
|
13
|
+
def MysqlShowStatusMonitor::description()
|
14
|
+
return "Check slow thread or query using mysql connection"
|
15
|
+
end
|
16
|
+
def MysqlShowStatusMonitor::name()
|
17
|
+
return "Check slow thread or query"
|
18
|
+
end
|
19
|
+
def MysqlShowStatusMonitor::default_severity()
|
20
|
+
return "MAJOR"
|
21
|
+
end
|
22
|
+
|
23
|
+
def monitor()
|
24
|
+
host=get_node().ip
|
25
|
+
database="mysql"
|
26
|
+
max_value=5
|
27
|
+
if ($mysql_lib_error!=false) && (get_node().get_account_id("mysql"))
|
28
|
+
username, password = get_node().get_account_id("mysql")
|
29
|
+
begin
|
30
|
+
# connect to the MySQL server
|
31
|
+
dbh = Mysql.real_connect(host, username, password, database)
|
32
|
+
# get server version string and display it
|
33
|
+
#puts "Server version: " + dbh.get_server_info
|
34
|
+
res = dbh.query("SHOW global status")
|
35
|
+
val=0
|
36
|
+
res.each do |row|
|
37
|
+
#printf "%s, %s\n", row[0], row[1]
|
38
|
+
if (row[0] == "Slow_launch_threads") || (row[0] == "Slow_queries")
|
39
|
+
val+=row[1].to_i()
|
40
|
+
end
|
41
|
+
end
|
42
|
+
#puts "Number of rows returned: #{res.num_rows}"
|
43
|
+
res.free
|
44
|
+
if val>max_value
|
45
|
+
set_state("CRITICAL","Mysql database slow status detected #{val} > #{max_value}")
|
46
|
+
else
|
47
|
+
set_state("NORMAL")
|
48
|
+
end
|
49
|
+
|
50
|
+
rescue Mysql::Error => e
|
51
|
+
#puts "Error code: #{e.errno}"
|
52
|
+
#puts "Error message: #{e.error}"
|
53
|
+
#puts "Error SQLSTATE: #{e.sqlstate}" if e.respond_to?("sqlstate")
|
54
|
+
raise(e)
|
55
|
+
ensure
|
56
|
+
# disconnect from server
|
57
|
+
dbh.close if dbh
|
58
|
+
end
|
59
|
+
else
|
60
|
+
$log.error("mysql login/password not set for host #{host}")
|
61
|
+
set_state("UNKNOWN")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require "#{GNMSLIB}"+'/monitor/custom_plugin'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'pg'
|
5
|
+
rescue LoadError
|
6
|
+
$log.fatal("PgsqlPercentConnectionMonitor: you need to install ruby-pg library for ruby")
|
7
|
+
$pg_lib_error=false
|
8
|
+
raise LoadError
|
9
|
+
end
|
10
|
+
|
11
|
+
class PgsqlPercentConnectionMonitor < CustomPlugin
|
12
|
+
#declare static methods
|
13
|
+
def PgsqlPercentConnectionMonitor::description()
|
14
|
+
return "Check max connection (in %) using postgres connection"
|
15
|
+
end
|
16
|
+
def PgsqlPercentConnectionMonitor::name()
|
17
|
+
return "Check max connection"
|
18
|
+
end
|
19
|
+
def PgsqlPercentConnectionMonitor::default_severity()
|
20
|
+
return "MAJOR"
|
21
|
+
end
|
22
|
+
|
23
|
+
def monitor()
|
24
|
+
host=get_node().ip
|
25
|
+
database="postgres"
|
26
|
+
max_value=95
|
27
|
+
pgport=5432
|
28
|
+
|
29
|
+
if ($pg_lib_error!= false) && (get_node().get_account_id("postgres"))
|
30
|
+
|
31
|
+
username, password = get_node().get_account_id("postgres")
|
32
|
+
begin
|
33
|
+
# connect to the PostgreSQL server
|
34
|
+
dbh = PGconn.connect(host, pgport, "", "", database, username, password)
|
35
|
+
|
36
|
+
val1=0
|
37
|
+
res = dbh.exec("SELECT COUNT(*) FROM pg_stat_activity")
|
38
|
+
if res.num_tuples > 0
|
39
|
+
val1=res.getvalue(0, 0)
|
40
|
+
end
|
41
|
+
res.clear
|
42
|
+
|
43
|
+
val2=0
|
44
|
+
res = dbh.exec("SHOW max_connections")
|
45
|
+
if res.num_tuples > 0
|
46
|
+
val2=res.getvalue(0, 0)
|
47
|
+
end
|
48
|
+
res.clear
|
49
|
+
|
50
|
+
print "Max connection (%) used #{val1}/#{val2}\n"
|
51
|
+
result=val1.to_f/val2.to_f
|
52
|
+
|
53
|
+
if result > max_value.to_f
|
54
|
+
set_state("CRITICAL","Postgresql database max connection reached #{result} > #{max_value.to_f}")
|
55
|
+
else
|
56
|
+
set_state("NORMAL")
|
57
|
+
end
|
58
|
+
|
59
|
+
rescue PGError => e
|
60
|
+
#puts "Error code: #{e.errno}"
|
61
|
+
#puts "Error message: #{e.error}"
|
62
|
+
raise(e)
|
63
|
+
ensure
|
64
|
+
# disconnect from server
|
65
|
+
dbh.close if dbh
|
66
|
+
end
|
67
|
+
else
|
68
|
+
$log.error("Postgresql 'postgres' login/password not set for host #{host}")
|
69
|
+
set_state("UNKNOWN")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require "#{GNMSLIB}"+'/monitor/custom_plugin'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'net/ssh'
|
5
|
+
rescue LoadError
|
6
|
+
$log.fatal("SshCpuLoadMonitor: you need to install net-ssh library for ruby")
|
7
|
+
raise LoadError
|
8
|
+
end
|
9
|
+
|
10
|
+
class SshCpuLoadMonitor < CustomPlugin
|
11
|
+
#declare static methods
|
12
|
+
def SshCpuLoadMonitor::description()
|
13
|
+
return "CPU load monitoring using Ssh connection to remotely read /proc/loadavg file"
|
14
|
+
end
|
15
|
+
def SshCpuLoadMonitor::name()
|
16
|
+
return "CPU load monitoring using Ssh"
|
17
|
+
end
|
18
|
+
def SshCpuLoadMonitor::parameter()
|
19
|
+
return 1.0
|
20
|
+
end
|
21
|
+
def SshCpuLoadMonitor::default_severity()
|
22
|
+
return "MAJOR"
|
23
|
+
end
|
24
|
+
|
25
|
+
def monitor()
|
26
|
+
host = get_node().ip
|
27
|
+
cmd = "cat /proc/loadavg"
|
28
|
+
max_cpuload = SshCpuLoadMonitor::parameter()
|
29
|
+
service_name = "ssh"
|
30
|
+
default_severity = SshCpuLoadMonitor::default_severity()
|
31
|
+
|
32
|
+
if get_node().get_account_id(service_name)
|
33
|
+
username, password = get_node().get_account_id(service_name)
|
34
|
+
define_port = 22
|
35
|
+
serv = get_node().service_by_name(service_name)
|
36
|
+
if serv
|
37
|
+
if serv.protocol == "tcp"
|
38
|
+
define_port = serv.port
|
39
|
+
else
|
40
|
+
raise("Could not run SshCpuLoadMonitor using other protocol than TCP")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
param = get_node().custom_parameter(self.class.to_s)
|
45
|
+
if (param != nil) and isDouble(param)
|
46
|
+
max_cpuload = param.to_f
|
47
|
+
end
|
48
|
+
|
49
|
+
sev = get_node().custom_severity(self.class.to_s)
|
50
|
+
if (sev != nil) and sev != ""
|
51
|
+
default_severity = sev
|
52
|
+
end
|
53
|
+
|
54
|
+
begin
|
55
|
+
Net::SSH.start(host, username, :password => password, :port => define_port) do |ssh|
|
56
|
+
channel = ssh.open_channel do |ch|
|
57
|
+
ch.exec cmd do |ch, success|
|
58
|
+
raise("Could not run SshCpuLoadMonitor on #{host}") unless success
|
59
|
+
ch.on_data do |c, data|
|
60
|
+
#we remove the linefeed the end
|
61
|
+
value=data.chomp.split(/\s/)[2]
|
62
|
+
if isDouble(value)
|
63
|
+
if value.to_f > max_cpuload.to_f
|
64
|
+
set_state(default_severity, "CPU load #{value} exceeded threshold #{max_cpuload}")
|
65
|
+
else
|
66
|
+
#set_state("NORMAL", "CPU load #{value.to_f * 100}%")
|
67
|
+
set_state("NORMAL")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
channel.wait
|
74
|
+
end
|
75
|
+
rescue Net::SSH::AuthenticationFailed
|
76
|
+
raise("SSH authentication failed for user=#{username}")
|
77
|
+
rescue Exception => msg
|
78
|
+
raise(msg)
|
79
|
+
end
|
80
|
+
else
|
81
|
+
$log.error("SSH login/password not set for ip=#{host}")
|
82
|
+
set_state("UNKNOWN", "SSH login/password not set")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require "#{GNMSLIB}"+'/monitor/custom_plugin'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'net/ssh'
|
5
|
+
rescue LoadError
|
6
|
+
$log.fatal("SshDiskMonitor: you need to install net-ssh library for ruby")
|
7
|
+
raise LoadError
|
8
|
+
end
|
9
|
+
|
10
|
+
class SshDiskMonitor < CustomPlugin
|
11
|
+
#declare static methods
|
12
|
+
def SshDiskMonitor::description()
|
13
|
+
return "Disk usage monitoring using SSH connection to remotely launch df command"
|
14
|
+
end
|
15
|
+
def SshDiskMonitor::name()
|
16
|
+
return "Disk usage monitoring using SSH"
|
17
|
+
end
|
18
|
+
def SshDiskMonitor::default_severity()
|
19
|
+
return "MAJOR"
|
20
|
+
end
|
21
|
+
|
22
|
+
def monitor()
|
23
|
+
host=get_node().ip
|
24
|
+
partition="/dev/sda1"
|
25
|
+
hardlimit_value=90
|
26
|
+
service_name = "ssh"
|
27
|
+
|
28
|
+
if get_node().get_account_id(service_name)
|
29
|
+
username, password = get_node().get_account_id(service_name)
|
30
|
+
define_port = 22
|
31
|
+
serv = get_node().service_by_name(service_name)
|
32
|
+
if serv
|
33
|
+
if serv.protocol == "tcp"
|
34
|
+
define_port = serv.port
|
35
|
+
else
|
36
|
+
raise("Could not run SshDiskMonitor using other protocol than TCP")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
begin
|
40
|
+
Net::SSH.start(host, username, :password => password, :port => define_port) do |ssh|
|
41
|
+
channel = ssh.open_channel do |ch|
|
42
|
+
ch.exec "df -lhP|grep #{partition} |awk '{ print $5; }'" do |ch, success|
|
43
|
+
raise("Could not run SshDiskMonitor on #{host}") unless success
|
44
|
+
ch.on_data do |c, data|
|
45
|
+
#we remove the linefeed and % char from the end
|
46
|
+
value=data.chomp.chop
|
47
|
+
if isInteger(value)
|
48
|
+
if value.to_i > hardlimit_value
|
49
|
+
set_state("CRITICAL", "Disk usage #{partition} exceeded > #{hardlimit_value}%")
|
50
|
+
else
|
51
|
+
set_state("NORMAL")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
channel.wait
|
58
|
+
end
|
59
|
+
rescue Net::SSH::AuthenticationFailed
|
60
|
+
raise("SSH authentication failed for user=#{username}")
|
61
|
+
rescue Exception => msg
|
62
|
+
raise(msg)
|
63
|
+
end
|
64
|
+
else
|
65
|
+
$log.error("SSH login/password not set for ip=#{host}")
|
66
|
+
set_state("UNKNOWN", "SSH login/password not set")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require "#{GNMSLIB}"+'/monitor/custom_plugin'
|
2
|
+
require 'date'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'net/ssh'
|
6
|
+
rescue LoadError
|
7
|
+
$log.fatal("SshFgtAvExpriredMonitor: you need to install ssh library for ruby")
|
8
|
+
raise LoadError
|
9
|
+
end
|
10
|
+
|
11
|
+
class SshFgtAvExpiredMonitor < CustomPlugin
|
12
|
+
#declare static methods
|
13
|
+
def SshFgtAvExpiredMonitor::description()
|
14
|
+
return "Check Fortigate AV definition expiration date using SSH"
|
15
|
+
end
|
16
|
+
def SshFgtAvExpiredMonitor::name()
|
17
|
+
return "Fortigate AV definition"
|
18
|
+
end
|
19
|
+
def SshFgtAvExpiredMonitor::default_severity()
|
20
|
+
return "MAJOR"
|
21
|
+
end
|
22
|
+
|
23
|
+
def monitor()
|
24
|
+
|
25
|
+
host=get_node().ip
|
26
|
+
nb_of_day=5
|
27
|
+
cmd="get system fortiguard-service status"
|
28
|
+
line_to_identify="Virus Definitions"
|
29
|
+
service_name = "ssh"
|
30
|
+
|
31
|
+
if get_node().get_account_id(service_name)
|
32
|
+
username, password = get_node().get_account_id(service_name)
|
33
|
+
define_port = 22
|
34
|
+
serv = get_node().service_by_name(service_name)
|
35
|
+
if serv
|
36
|
+
if serv.protocol == "tcp"
|
37
|
+
define_port = serv.port
|
38
|
+
else
|
39
|
+
raise("Could not run SshFgtAvExpiredMonitor using other protocol than TCP")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
begin
|
43
|
+
Net::SSH.start(host, username, :password => password, :port => define_port) do |ssh|
|
44
|
+
channel = ssh.open_channel do |ch|
|
45
|
+
ch.exec "#{cmd}" do |ch, success|
|
46
|
+
raise("could not run SshFgtAvExpriredMonitor on #{host}") unless success
|
47
|
+
ch.on_data do |c, data|
|
48
|
+
#we remove the linefeed and % char from the end
|
49
|
+
if data.match(line_to_identify)
|
50
|
+
#check last update
|
51
|
+
resultt=data.chomp.gsub(line_to_identify,"").split("\s")
|
52
|
+
last_update_day=resultt[1]
|
53
|
+
max_date=Date.today-nb_of_day
|
54
|
+
if Date.parse(last_update_day) < max_date
|
55
|
+
set_state("CRITICAL", "Fortigate AV definition expired, older than #{max_date}")
|
56
|
+
else
|
57
|
+
set_state("NORMAL")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
channel.wait
|
64
|
+
end
|
65
|
+
rescue Net::SSH::AuthenticationFailed
|
66
|
+
raise("SSH authentication failed for user=#{username}")
|
67
|
+
rescue Exception => msg
|
68
|
+
raise(msg)
|
69
|
+
end
|
70
|
+
else
|
71
|
+
$log.error("SSH login/password not set for ip=#{host}")
|
72
|
+
set_state("UNKNOWN", "SSH login/password not set")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require "#{GNMSLIB}"+'/monitor/custom_plugin'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'net/ssh'
|
5
|
+
rescue LoadError
|
6
|
+
$log.fatal("SshPercentUsedRamMonitor: you need to install net-ssh library for ruby")
|
7
|
+
raise LoadError
|
8
|
+
end
|
9
|
+
|
10
|
+
class SshPercentUsedRamMonitor < CustomPlugin
|
11
|
+
#declare static methods
|
12
|
+
def SshPercentUsedRamMonitor::description()
|
13
|
+
return "% used RAM monitoring using Ssh connection to remotely run free cli cmd"
|
14
|
+
end
|
15
|
+
def SshPercentUsedRamMonitor::name()
|
16
|
+
return "% used RAM monitoring using Ssh"
|
17
|
+
end
|
18
|
+
def SshPercentUsedRamMonitor::default_severity()
|
19
|
+
return "MAJOR"
|
20
|
+
end
|
21
|
+
|
22
|
+
def monitor()
|
23
|
+
host=get_node().ip
|
24
|
+
cmd="/usr/bin/free | grep 'Mem'"
|
25
|
+
max_mem_used=50
|
26
|
+
service_name = "ssh"
|
27
|
+
|
28
|
+
if get_node().get_account_id(service_name)
|
29
|
+
username, password = get_node().get_account_id(service_name)
|
30
|
+
define_port = 22
|
31
|
+
serv = get_node().service_by_name(service_name)
|
32
|
+
if serv
|
33
|
+
if serv.protocol == "tcp"
|
34
|
+
define_port = serv.port
|
35
|
+
else
|
36
|
+
raise("Could not run SshPercentUsedRamMonitor using other protocol than TCP")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
begin
|
40
|
+
Net::SSH.start(host, username, :password => password, :port => define_port) do |ssh|
|
41
|
+
channel = ssh.open_channel do |ch|
|
42
|
+
ch.exec cmd do |ch, success|
|
43
|
+
raise("Could not run SshPercentUsedRamMonitor on #{host}") unless success
|
44
|
+
ch.on_data do |c, data|
|
45
|
+
#we remove the linefeed the end
|
46
|
+
value = data.chomp.split(/\s+/)
|
47
|
+
mem_total = value[1]
|
48
|
+
mem_used = value[2]
|
49
|
+
|
50
|
+
result = mem_used.to_f * 100.0 / mem_total.to_f
|
51
|
+
|
52
|
+
if result >= 0.0 and result <= 100
|
53
|
+
if result > max_mem_used.to_f
|
54
|
+
set_state("CRITICAL", "Used RAM #{result.floor}% exceeded threshold #{max_mem_used}%")
|
55
|
+
else
|
56
|
+
set_state("NORMAL")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
channel.wait
|
63
|
+
end
|
64
|
+
rescue Net::SSH::AuthenticationFailed
|
65
|
+
raise("SSH authentication failed for user=#{username}")
|
66
|
+
rescue Exception => msg
|
67
|
+
raise(msg)
|
68
|
+
end
|
69
|
+
else
|
70
|
+
$log.error("SSH login/password not set for ip=#{host}")
|
71
|
+
set_state("UNKNOWN", "SSH login/password not set")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|