opstat-plugins 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.gitlab-ci.yml +17 -0
  4. data/LICENSE +675 -0
  5. data/lib/app/models/apache2.rb +192 -0
  6. data/lib/app/models/bsdnet/bytes_in_out.rb +54 -0
  7. data/lib/app/models/bsdnet/current_entries.rb +34 -0
  8. data/lib/app/models/bsdnet.rb +12 -0
  9. data/lib/app/models/cpu.rb +86 -0
  10. data/lib/app/models/disk.rb +51 -0
  11. data/lib/app/models/disk_io.rb +53 -0
  12. data/lib/app/models/facts.rb +30 -0
  13. data/lib/app/models/fpm.rb +138 -0
  14. data/lib/app/models/haproxy.rb +57 -0
  15. data/lib/app/models/jvm.rb +51 -0
  16. data/lib/app/models/load.rb +99 -0
  17. data/lib/app/models/memory.rb +55 -0
  18. data/lib/app/models/nagios.rb +51 -0
  19. data/lib/app/models/network.rb +58 -0
  20. data/lib/app/models/oracle_fras_sizes.rb +41 -0
  21. data/lib/app/models/oracle_sessions.rb +43 -0
  22. data/lib/app/models/oracle_tablespaces_sizes.rb +51 -0
  23. data/lib/app/models/temper.rb +51 -0
  24. data/lib/app/models/webobjects.rb +83 -0
  25. data/lib/app/models/xen.rb +99 -0
  26. data/lib/data/hp_pdu.yml +191 -0
  27. data/lib/logging.rb +29 -0
  28. data/lib/opstat-plugins.rb +44 -0
  29. data/lib/parsers/apache2.rb +19 -0
  30. data/lib/parsers/bsdnet.rb +29 -0
  31. data/lib/parsers/cpu.rb +42 -0
  32. data/lib/parsers/disk.rb +49 -0
  33. data/lib/parsers/facts.rb +12 -0
  34. data/lib/parsers/fpm.rb +31 -0
  35. data/lib/parsers/freeswitch_fifos.rb +63 -0
  36. data/lib/parsers/haproxy.rb +34 -0
  37. data/lib/parsers/haproxy_tables.rb +25 -0
  38. data/lib/parsers/hp_pdu.rb +36 -0
  39. data/lib/parsers/jvm.rb +22 -0
  40. data/lib/parsers/load.rb +20 -0
  41. data/lib/parsers/memory.rb +29 -0
  42. data/lib/parsers/nagios.rb +39 -0
  43. data/lib/parsers/network.rb +37 -0
  44. data/lib/parsers/oracle_fras_sizes.rb +25 -0
  45. data/lib/parsers/oracle_sessions.rb +20 -0
  46. data/lib/parsers/oracle_tablespaces_sizes.rb +22 -0
  47. data/lib/parsers/temper.rb +17 -0
  48. data/lib/parsers/webobjects.rb +33 -0
  49. data/lib/parsers/xen.rb +39 -0
  50. data/lib/plugins/apache2.rb +76 -0
  51. data/lib/plugins/bsdnet.rb +13 -0
  52. data/lib/plugins/cpu.rb +13 -0
  53. data/lib/plugins/custom_sql_statement.rb +24 -0
  54. data/lib/plugins/disk.rb +31 -0
  55. data/lib/plugins/facts.rb +30 -0
  56. data/lib/plugins/fpm.rb +33 -0
  57. data/lib/plugins/freeswitch_fifos.rb +27 -0
  58. data/lib/plugins/haproxy.rb +24 -0
  59. data/lib/plugins/haproxy_tables.rb +28 -0
  60. data/lib/plugins/hp_pdu.rb +28 -0
  61. data/lib/plugins/jvm.rb +23 -0
  62. data/lib/plugins/load.rb +20 -0
  63. data/lib/plugins/memory.rb +18 -0
  64. data/lib/plugins/nagios.rb +39 -0
  65. data/lib/plugins/network.rb +21 -0
  66. data/lib/plugins/oracle_fras_sizes.rb +48 -0
  67. data/lib/plugins/oracle_sessions.rb +47 -0
  68. data/lib/plugins/oracle_tablespaces_sizes.rb +59 -0
  69. data/lib/plugins/temper.rb +21 -0
  70. data/lib/plugins/webobjects.rb +42 -0
  71. data/lib/plugins/xen.rb +22 -0
  72. data/opstat-plugins.gemspec +20 -0
  73. data/spec/cpu_spec.rb +39 -0
  74. data/spec/disk_io_spec.rb +31 -0
  75. data/spec/disk_spec.rb +31 -0
  76. data/spec/fixtures/parser_cpu_16_core.txt +24 -0
  77. data/spec/fixtures/parser_cpu_16_core_corrupted.txt +24 -0
  78. data/spec/fixtures/parser_cpu_single_core.txt +10 -0
  79. data/spec/fixtures/parser_cpu_single_core_corrupted.txt +9 -0
  80. data/spec/fixtures/parser_disk_3_mounts.txt +9 -0
  81. data/spec/fixtures/parser_disk_corrupted.txt +9 -0
  82. data/spec/fixtures/parser_disk_io.txt +2 -0
  83. data/spec/fixtures/parser_disk_io_corrupted.txt +2 -0
  84. data/spec/fixtures/parser_haproxy_correct.txt +2 -0
  85. data/spec/fixtures/parser_haproxy_corrupted.txt +2 -0
  86. data/spec/fixtures/parser_haproxy_many_frontend_many_backend.txt +6 -0
  87. data/spec/fixtures/parser_haproxy_single_frontend_single_backend_with_single_svname.txt +5 -0
  88. data/spec/fixtures/parser_load.txt +1 -0
  89. data/spec/fixtures/parser_load_corrupted.txt +2 -0
  90. data/spec/fixtures/parser_memory.txt +43 -0
  91. data/spec/fixtures/parser_memory_corrupted.txt +43 -0
  92. data/spec/fixtures/parser_network.txt +5 -0
  93. data/spec/fixtures/parser_network_corrupted.txt +5 -0
  94. data/spec/fixtures/parser_webobjects_many_apps_many_instances.result.yml +590 -0
  95. data/spec/fixtures/parser_webobjects_many_apps_many_instances.txt +2 -0
  96. data/spec/fixtures/parser_webobjects_one_app_many_instances.result.yml +305 -0
  97. data/spec/fixtures/parser_webobjects_one_app_many_instances.txt +395 -0
  98. data/spec/haproxy_spec.rb +68 -0
  99. data/spec/load_spec.rb +21 -0
  100. data/spec/memory_spec.rb +21 -0
  101. data/spec/network_spec.rb +21 -0
  102. data/spec/spec_helper.rb +102 -0
  103. data/spec/webobjects_spec.rb +28 -0
  104. metadata +189 -0
@@ -0,0 +1,36 @@
1
+ module Opstat
2
+ module Parsers
3
+ class HpPdu
4
+ include Opstat::Logging
5
+
6
+ def snmp_ids
7
+ @snmp_ids ||= YAML::load_file("#{File.dirname(File.expand_path(__FILE__))}/../data/hp_pdu.yml")
8
+ @snmp_ids
9
+ end
10
+
11
+ def parse_data(data:, time:)
12
+ return if data.nil? #TODO EVENT IN db
13
+ temp = {}
14
+ begin
15
+ ids = data.split("\n")
16
+ ids.each do |id|
17
+ k, v = id.split(' = ')
18
+ if self.snmp_ids.has_key?(k)
19
+ props = snmp_ids[k]
20
+ temp_key = "#{props[:meter_type]}#{props[:pdu]}"
21
+ temp[temp_key] ||= {:meter_type => props[:meter_type], :pdu => props[:pdu]}
22
+ temp[temp_key][props[:store_key]] = v.split(': ')[-1].to_i
23
+ end
24
+ end
25
+
26
+ rescue
27
+ #TODO find best way to deal with that kind of problems
28
+ #TODO check if timestamp > prev
29
+ return
30
+ end
31
+ reports = temp.values
32
+ return reports
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,22 @@
1
+ module Opstat
2
+ module Parsers
3
+ class Jvm
4
+ include Opstat::Logging
5
+
6
+ def parse_data(data:, time:)
7
+ return if data.nil? #TODO EVENT IN db
8
+
9
+ begin
10
+ data.split("\n").each do |line|
11
+ oplogger.debug "parsing line #{line}"
12
+ end
13
+ rescue
14
+ #TODO find best way to deal with that kind of problems
15
+ #TODO check if timestamp > prev
16
+ return
17
+ end
18
+ return report
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ module Opstat
2
+ module Parsers
3
+ class Load
4
+ include Opstat::Logging
5
+
6
+ def parse_data(data:, time:)
7
+ data.find{|a| a =~ /^(?<load_1m>\S+)\s+(?<load_5m>\S+)\s+(?<load_15m>\S+)\s+(?<threads_running>\d+)\/(?<threads>\d+).*/}
8
+ return [] if $~.nil?
9
+ # TODO add some alert to system - bad input data
10
+ return [{
11
+ :load_1m => $~[:load_1m].to_f,
12
+ :load_5m => $~[:load_5m].to_f,
13
+ :load_15m => $~[:load_15m].to_f,
14
+ :threads_running => $~[:threads_running].to_i,
15
+ :threads => $~[:threads].to_i
16
+ }]
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,29 @@
1
+ require 'yaml'
2
+
3
+ module Opstat
4
+ module Parsers
5
+ class Memory
6
+ include Opstat::Logging
7
+
8
+ def parse_data(data:, time:)
9
+ memory = YAML::load(data.join)
10
+ oplogger.debug memory
11
+ begin
12
+ return [{
13
+ :total => memory["MemTotal"].split[0].to_i,
14
+ :free => memory["MemFree"].split[0].to_i,
15
+ :used => memory["MemTotal"].split[0].to_i - memory["MemFree"].split[0].to_i - (memory["Buffers"].to_i + memory["Cached"].split[0].to_i + memory["SReclaimable"].split[0].to_i - memory["Shmem"].split[0].to_i),
16
+ :cached => memory["Cached"].split[0].to_i + memory["SReclaimable"].split[0].to_i - memory["Shmem"].split[0].to_i,
17
+ :buffers => memory["Buffers"].split[0].to_i,
18
+ :swap_total => memory["SwapTotal"].split[0].to_i,
19
+ :swap_free => memory["SwapFree"].split[0].to_i,
20
+ :swap_used => memory["SwapTotal"].split[0].to_i - memory["SwapFree"].split[0].to_i
21
+ }]
22
+ rescue Exception => e
23
+ return []
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+
@@ -0,0 +1,39 @@
1
+ module Opstat
2
+ module Parsers
3
+ class Nagios
4
+ include Opstat::Logging
5
+
6
+ def parse_data(data:, time:)
7
+ report = {}
8
+ begin
9
+ data.compact.each do |elem|
10
+ v = elem.strip.split(':')
11
+ next if v.length == 0
12
+ next if v.count != 2
13
+ key = v[0].strip
14
+ val = v[1].strip
15
+ report[key] = val
16
+ end
17
+ rescue
18
+ #TODO add errors to gui - bad data
19
+ return
20
+ end
21
+ report["Hosts Up"], report["Hosts Down"], report["Hosts Unreachable"] = report["Hosts Up/Down/Unreach"].split('/')
22
+ report["Services Ok"], report["Services Warning"], report["Services Unknown"], report["Services Critical"] = report["Services Ok/Warn/Unk/Crit"].split('/')
23
+ return [{
24
+ :services_total => report["Total Services"],
25
+ :hosts_total => report["Total Hosts"],
26
+ :services_checked => report["Services Checked"],
27
+ :hosts_checked => report["Hosts Checked"],
28
+ :services_ok => report["Services Ok"],
29
+ :services_warning => report["Services Warning"],
30
+ :services_critical => report["Services Critical"],
31
+ :services_unknown => report["Services Unknown"],
32
+ :hosts_up => report["Hosts Up"],
33
+ :hosts_down => report["Hosts Down"],
34
+ :hosts_unreachable => report ["Hosts Unreachable"]
35
+ }]
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,37 @@
1
+ module Opstat
2
+ module Parsers
3
+ class Network
4
+ include Opstat::Logging
5
+
6
+ def parse_data(data:, time:)
7
+ reports = []
8
+ interfaces_stats = data[2..-1].map{|u| u.lstrip}.join.split("\n")
9
+ interfaces_stats.each do |interface_stat|
10
+ interface, values = interface_stat.split(':')
11
+ next if values.nil?
12
+ v = values.split
13
+ reports << {
14
+ :OPSTAT_TAG_interface => interface,
15
+ :bytes_receive => v[0].to_i,
16
+ :packets_receive => v[1].to_i,
17
+ :errors_receive => v[2].to_i,
18
+ :drop_receive => v[3].to_i,
19
+ :fifo_receive => v[4].to_i,
20
+ :frame_receive => v[5].to_i,
21
+ :compressed_receive => v[6].to_i,
22
+ :multicast_receive => v[7].to_i,
23
+ :bytes_transmit => v[8].to_i,
24
+ :packets_transmit => v[9].to_i,
25
+ :errors_transmit => v[10].to_i,
26
+ :drop_transmit => v[11].to_i,
27
+ :fifo_transmit => v[12].to_i,
28
+ :frame_transmit => v[13].to_i,
29
+ :compressed_transmit => v[14].to_i,
30
+ :multicast_transmit => v[15].to_i
31
+ }
32
+ end
33
+ return reports
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,25 @@
1
+ module Opstat
2
+ module Parsers
3
+ class OracleFrasSizes
4
+ include Opstat::Logging
5
+
6
+ #TODO - somehow check plugins version
7
+ def parse_data(data:, time:)
8
+ reports = []
9
+ data.split("\n")[3..-1].each do |line|
10
+ tablespace = line.split(/\s+/).delete_if{|t| t.empty?}
11
+ total = tablespace[1].to_i
12
+ used = tablespace[2].to_i
13
+ free = total - used
14
+ reports << {
15
+ :OPSTAT_TAG_path => tablespace[0],
16
+ :free => free,
17
+ :used => used,
18
+ :files => tablespace[3].to_i
19
+ }
20
+ end
21
+ return reports
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ module Opstat
2
+ module Parsers
3
+ class OracleSessions
4
+ include Opstat::Logging
5
+
6
+ #TODO - somehow check plugins version
7
+ def parse_data(data:, time:)
8
+ reports = []
9
+ data.split("\n")[3..-1].each do |line|
10
+ tablespace = line.split(/\s+/).delete_if{|t| t.empty?}
11
+ reports << {
12
+ :used => tablespace[0].to_i,
13
+ :free => tablespace[1].to_i
14
+ }
15
+ end
16
+ return reports
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ module Opstat
2
+ module Parsers
3
+ class OracleTablespacesSizes
4
+ include Opstat::Logging
5
+
6
+ #TODO - somehow check plugins version
7
+ def parse_data(data:, time:)
8
+ reports = []
9
+ data.split("\n")[3..-3].each do |line|
10
+ tablespace = line.split(/\s+/).delete_if{|t| t.empty?}
11
+ reports << {
12
+ :OPSTAT_TAG_tablespace => tablespace[0],
13
+ :total => tablespace[1].to_i,
14
+ :used => tablespace[2].to_i,
15
+ :free => tablespace[3].to_i
16
+ }
17
+ end
18
+ return reports
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,17 @@
1
+ module Opstat
2
+ module Parsers
3
+ require 'json'
4
+ class Temper
5
+ include Opstat::Logging
6
+
7
+ def parse_data(data:, time:)
8
+ #TODO - mesg when empty
9
+ temperature = data.split(',')[1].to_f
10
+ temperature = JSON::parse(data)["temperature_celsius"]
11
+ return [{
12
+ :temperature => temperature
13
+ }]
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,33 @@
1
+ require 'json'
2
+
3
+ module Opstat
4
+ module Parsers
5
+ class Webobjects
6
+ include Opstat::Logging
7
+
8
+ def parse_data(data:, time:)
9
+ return if data.length == 0
10
+ reports = []
11
+ prepared_data = data.gsub('"id"','"instance_id"')
12
+ webobjects_json_stats = JSON::parse(prepared_data)
13
+ webobjects_json_stats.select{|s| s['state'] == 'ALIVE'}.each do |instance_stats|
14
+ webobjects_stats = {
15
+ 'active_sessions': instance_stats['activeSessions'].to_i,
16
+ 'transactions': instance_stats['transactions'].to_i,
17
+ 'average_idle_period': instance_stats['averageIdlePeriod'].to_f,
18
+ 'average_transaction_time': instance_stats['avgTransactionTime'].to_f,
19
+ 'deaths': instance_stats['deaths'].to_i,
20
+ 'refusing_new_sessions': instance_stats['refusingNewSessions'],
21
+ 'auto_recover': instance_stats['autoRecover'].downcase == 'true',
22
+ 'OPSTAT_TAG_wo_instance_id': instance_stats['instance_id'],
23
+ 'OPSTAT_TAG_wo_host': instance_stats['host'],
24
+ 'OPSTAT_TAG_wo_app': instance_stats['name']
25
+ }
26
+ reports << webobjects_stats
27
+ end
28
+ return reports
29
+ end
30
+ end
31
+ end
32
+ end
33
+
@@ -0,0 +1,39 @@
1
+ module Opstat
2
+ module Parsers
3
+ class Xen
4
+ include Opstat::Logging
5
+
6
+ def parse_data(data:, time:)
7
+ return if data.nil?
8
+ domains = []
9
+
10
+ begin
11
+ data.split("\n")[1..-1].each do |line|
12
+ oplogger.debug "parsing line #{line}"
13
+ domain = {}
14
+ stats = line.split
15
+
16
+ domain['domain'] = stats[0]
17
+ domain['cpu'] = stats[3].to_i
18
+ domain['memory'] = stats[4].to_i
19
+ domain['memory_max'] = stats[6].to_i
20
+ domain['nettx'] = stats[10].to_i
21
+ domain['netrx'] = stats[11].to_i
22
+ domain['vbd_oo'] = stats[13].to_i
23
+ domain['vbd_rd'] = stats[14].to_i
24
+ domain['vbd_wr'] = stats[15].to_i
25
+ domain['vbd_rsect'] = stats[16].to_i
26
+ domain['vbd_wsect'] = stats[17].to_i
27
+ domains << domain
28
+ end
29
+ rescue
30
+ #TODO find best way to deal with that kind of problems
31
+ #TODO check if timestamp > prev
32
+ return
33
+ end
34
+ #TODO batch import?
35
+ return domains
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,76 @@
1
+ module Opstat
2
+ module Plugins
3
+
4
+ class Apache2 < Task
5
+
6
+ def initialize (name, queue, config)
7
+ super(name, queue, config)
8
+ self
9
+ end
10
+
11
+ def parse
12
+ return @external_plugin[:object].get
13
+ end
14
+
15
+ def set_external_plugin=(external)
16
+ @external_plugin[:object] = external
17
+ end
18
+
19
+ def external_plugin
20
+ return @external_plugin
21
+ end
22
+ end
23
+
24
+ module UDPExternalPlugins
25
+ class Apache2 < EventMachine::Connection
26
+ include Logging
27
+ def initialize(options)
28
+ @log_level = options['log_level'] if options.has_key?('log_level')
29
+ oplogger.info "Create external plugin"
30
+ oplogger.debug "External plugin options :#{options}"
31
+ require 'json'
32
+ require 'apachelogregex'
33
+ @log_format = options['log_format']
34
+ @log_format ||= '%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O'
35
+ @stat = Hash.new
36
+ @parser = ApacheLogRegex.new(@log_format)
37
+ end
38
+ def post_init
39
+ oplogger.debug "someone connected!"
40
+ end
41
+
42
+ #TODO - something with parse everty line - skips some correct lines
43
+ def receive_data data
44
+ oplogger.debug data
45
+ line = data.split(': ')[1]
46
+ parse(line)
47
+ end
48
+
49
+ def unbind
50
+ oplogger.debug "someone disconnected!"
51
+ end
52
+
53
+ def parse(line)
54
+ data = @parser.parse(line)
55
+ if data
56
+ oplogger.debug data
57
+ @stat[data['%v'] ] ||= Hash.new
58
+ @stat[data['%v'] ] [data['%>s']] ||= Hash.new
59
+ @stat[data['%v'] ] [data['%>s']] [:requests] ||= 0
60
+ @stat[data['%v'] ] [data['%>s']] [:requests] += 1
61
+ @stat[data['%v'] ] [data['%>s']] [:bytes_sent] ||= 0
62
+ @stat[data['%v'] ] [data['%>s']] [:bytes_sent] += data['%O'].to_i
63
+ end
64
+ end
65
+
66
+ def get
67
+ @stat.to_json
68
+ end
69
+ end
70
+ end
71
+
72
+ end
73
+ end
74
+ #TO CHECK - port not used
75
+ # apache log format configured, apache logger configured
76
+ # TODO apachelogregex - installed?
@@ -0,0 +1,13 @@
1
+ module Opstat
2
+ module Plugins
3
+ class Bsdnet < Task
4
+ def parse
5
+ io = IO.popen("pfctl -sinfo")
6
+ report = io.readlines
7
+ io.close
8
+ return report
9
+ end
10
+ end
11
+ end
12
+ end
13
+ #TODO check if stats are activated - set logininterfacep works only for one interface
@@ -0,0 +1,13 @@
1
+ module Opstat
2
+ module Plugins
3
+ class Cpu < Task
4
+ STAT_FILE = "/proc/stat"
5
+
6
+ def parse
7
+ report = File.readlines(STAT_FILE)
8
+ return report
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,24 @@
1
+ require 'active_record'
2
+
3
+ module Opstat
4
+ module Plugins
5
+ class CustomSqlStatement < Task
6
+
7
+ def initialize (name, queue, config)
8
+ super(name, queue, config)
9
+ self
10
+ @db_config = config['db_config']
11
+ @query - config['sql_query']
12
+ ActiveRecord::Base.establish_connection @dbconfig
13
+ end
14
+
15
+ def parse
16
+ report = ActiveRecord::Base.connection.execute(@query)
17
+ return report
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+ #need:
24
+ #activerecord gem
@@ -0,0 +1,31 @@
1
+ module Opstat
2
+ module Plugins
3
+ class Disk < Task
4
+ DISK_IO_STATS_FILE = "/proc/diskstats"
5
+
6
+ def initialize (name, queue, config)
7
+ super(name, queue, config)
8
+ self
9
+ end
10
+
11
+ #TODO in memory module io.close
12
+ def parse
13
+ @count_number += 1
14
+ report = {}
15
+ report['disk_space'] = space_usage
16
+ report['disk_io'] = disk_io_usage
17
+ return report
18
+ end
19
+ def space_usage
20
+ io = IO.popen('df --output=source,fstype,used,avail,itotal,iused,iavail,target|sed "s#/dev/root#/dev/$(readlink /dev/root)#"')
21
+ stats = io.readlines
22
+ io.close
23
+ return stats
24
+ end
25
+ def disk_io_usage
26
+ stats = File.open(DISK_IO_STATS_FILE).readlines
27
+ return stats
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,30 @@
1
+ #set default FACTERDIR - omit libfacter not found on some systems
2
+ facter_paths = ['/usr','/usr/lib']
3
+ facter_paths << ENV['FACTERDIR'] unless ENV['FACTERDIR'].nil?
4
+ begin
5
+ facter_path = facter_paths.pop
6
+ ENV['FACTERDIR'] = facter_path
7
+ puts "Try to load facter lib with FACTERDIR path set to #{facter_path}"
8
+ require 'facter'
9
+ rescue LoadError => e
10
+ retry if facter_paths.count > 0
11
+ raise e
12
+ end
13
+
14
+ module Opstat
15
+ module Plugins
16
+ class Facts < Task
17
+
18
+ def initialize (name, queue, config)
19
+ super(name, queue, config)
20
+ self
21
+ end
22
+
23
+ #TODO in memory module io.close
24
+ def parse
25
+ @count_number += 1
26
+ return ::Facter.to_hash
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,33 @@
1
+ module Opstat
2
+ module Plugins
3
+ class Fpm < Task
4
+ require 'json'
5
+
6
+ def initialize (name, queue, config)
7
+ super(name, queue, config)
8
+ @pools = config['pools']
9
+ self
10
+ end
11
+
12
+ def parse
13
+ report = []
14
+ @pools.each_pair do |pool,options|
15
+ oplogger.debug "getting #{pool} statistics"
16
+ env = {"REQUEST_METHOD" => options['request_method'], "SCRIPT_NAME" => options['status_url'], "SCRIPT_FILENAME" => options['status_url'], "QUERY_STRING" => 'json'}
17
+ oplogger.debug "cgi-fcgi environment: #{env.inspect}"
18
+ fpmIO = IO.popen([env, 'cgi-fcgi','-bind','-connect',options['fcgi_socket'] ])
19
+ pool_report = fpmIO.readlines
20
+ oplogger.debug "#{pool} statistics: #{pool_report}"
21
+ report << pool_report
22
+ fpmIO.close
23
+ end
24
+ return report
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ #TO CHECK -cgi-fcgi installed
31
+ #- pm.status_path property set in pool configuration
32
+
33
+
@@ -0,0 +1,27 @@
1
+ require 'xmlhasher'
2
+
3
+ module Opstat
4
+ module Plugins
5
+ class FreeswitchFifos < Task
6
+ def initialize (name, queue, config)
7
+ merged_config = default_config.merge(config)
8
+ super(name, queue, merged_config)
9
+ @fifo_report_cmd = merged_config['fifo_report_cmd']
10
+ self
11
+ end
12
+
13
+ def parse
14
+ @count_number += 1
15
+ report = `#{@fifo_report_cmd}`
16
+ return report
17
+ end
18
+
19
+ def default_config
20
+ {
21
+ 'fifo_report_cmd' => 'fs_cli -x \'fifo list\''
22
+ }
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,24 @@
1
+ require 'open-uri'
2
+ module Opstat
3
+ module Plugins
4
+
5
+ class Haproxy < Task
6
+ def initialize (name, queue, config)
7
+ super(name, queue, config)
8
+ @haproxy_url = "#{config['url']}/;up/stats;csv;norefresh'"
9
+ self
10
+ end
11
+ def parse
12
+ report = []
13
+ begin
14
+ source = open(@haproxy_url,open_timeout: 1, read_timeout: 1).each do |line|
15
+ report << line
16
+ end
17
+ rescue
18
+ nil
19
+ end
20
+ return report
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ require 'socket'
2
+
3
+ module Opstat
4
+ module Plugins
5
+
6
+ class HaproxyTables < Task
7
+ def initialize (name, queue, config)
8
+ super(name, queue, config)
9
+ @haproxy_socket = config['socket']
10
+ raise ArgumentError, "Socket #{path} doesn't exists or is not a UNIX socket" unless File.exists?(@haproxy_socket) and File.socket?(@haproxy_socket)
11
+ self
12
+ end
13
+
14
+ def parse
15
+ report = []
16
+ begin
17
+ UNIXSocket.open(@haproxy_socket) do |socket|
18
+ socket.puts('show table')
19
+ report = socket.readlines
20
+ end
21
+ rescue
22
+ nil
23
+ end
24
+ return report
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ require 'yaml'
2
+ module Opstat
3
+ module Plugins
4
+ class HpPdu < Task
5
+ def initialize (name, queue, config)
6
+ super(name, queue, config)
7
+ @snmp_host = config['snmp_host']
8
+ @snmp_port = config['snmp_port']
9
+ pwd = File.dirname(File.expand_path(__FILE__))
10
+ snmp_ids = YAML::load_file("#{pwd}/../data/hp_pdu.yml").keys.join(' ')
11
+ @snmp_cmd = "snmpget -c public -v2c #{@snmp_host}:#{@snmp_port} #{snmp_ids}"
12
+ end
13
+
14
+ def parse
15
+ snmpIO = IO.popen(@snmp_cmd)
16
+ report = snmpIO.readlines.join
17
+ snmpIO.close
18
+ return report
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+
25
+
26
+ #for test
27
+ # check snmp is installed
28
+ # check port is open - snmp is accessible