onering-report-plugins 0.0.39 → 0.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,90 @@
1
+ require 'resolv'
2
+
3
+ protocols = %w{tcp}
4
+
5
+ flags = "--numeric-hosts --numeric-ports --programs --tcp -ee"
6
+
7
+ case Facter.value('osfamily').to_s.downcase
8
+ when 'debian' then flags += " -W"
9
+ when 'redhat' then flags += " -T"
10
+ end
11
+
12
+ listening = Facter::Util::Resolution.exec("nice -n 19 netstat #{flags} -l | tr -s ' '")
13
+ #nonlistening = Facter::Util::Resolution.exec("nice -n 19 netstat #{flags} | tr -s ' '")
14
+
15
+ # netstat = {
16
+ # 'listening' => [],
17
+ # 'connections' => []
18
+ # }
19
+
20
+ netstat = {
21
+ 'listening' => []
22
+ }
23
+
24
+ def getcommandline(pid)
25
+ return nil unless pid.to_i > 0
26
+ (File.read("/proc/#{pid}/cmdline").to_s.strip.chomp.squeeze("\u0000").squeeze("\0").gsub("\u0000", ' ').gsub("\0", ' '))
27
+ end
28
+
29
+ listening.lines.to_a[2..-1].each do |line|
30
+ protocol, recvq, sendq, local, foreign, state, user, inode, program = line.split(' ', 9)
31
+ next unless protocols.include?(protocol)
32
+
33
+ local = local.split(':')
34
+ foreign = foreign.split(':')
35
+ local_host = local[-2]
36
+ local_port = local[-1]
37
+ foreign_host = foreign[-2]
38
+ foreign_port = foreign[-1]
39
+ pid = program.split('/').first
40
+
41
+ netstat['listening'] << {
42
+ "protocol" => protocol,
43
+ "address" => local_host,
44
+ "fqdn" => (Resolv.getname(local_host) rescue nil),
45
+ "port" => local_port.to_i,
46
+ "user" => user,
47
+ "program" => {
48
+ "pid" => pid.to_i,
49
+ "command" => getcommandline(pid)
50
+ }
51
+ }
52
+ end
53
+
54
+ # nonlistening.lines.to_a[2..-1].each do |line|
55
+ # protocol, recvq, sendq, local, foreign, state, user, inode, program = line.split(' ', 9)
56
+ # next unless protocols.include?(protocol)
57
+
58
+ # local = local.split(':')
59
+ # foreign = foreign.split(':')
60
+ # local_host = local[-2]
61
+ # local_port = local[-1]
62
+ # foreign_host = foreign[-2]
63
+ # foreign_port = foreign[-1]
64
+ # pid = program.split('/').first
65
+
66
+ # netstat['connections'] << {
67
+ # "protocol" => protocol,
68
+ # "from" => {
69
+ # "address" => local_host,
70
+ # "port" => local_port.to_i
71
+ # },
72
+ # "to" => {
73
+ # "address" => foreign_host,
74
+ # "fqdn" => (Resolv.getname(foreign_host) rescue nil),
75
+ # "port" => foreign_port.to_i
76
+ # },
77
+ # "user" => user,
78
+ # "state" => state.downcase,
79
+ # "program" => {
80
+ # "pid" => pid.to_i,
81
+ # "command" => getcommandline(pid)
82
+ # }
83
+ # }
84
+ # end
85
+
86
+ Facter.add("netstat") do
87
+ setcode do
88
+ netstat
89
+ end
90
+ end
@@ -54,6 +54,7 @@ report do
54
54
 
55
55
  property :network, {
56
56
  :@ip => ips,
57
- :@interfaces => interfaces.values
57
+ :@interfaces => interfaces.values,
58
+ :@sockets => Facter.value('netstat')
58
59
  }
59
60
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onering-report-plugins
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.39
4
+ version: 0.0.40
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-04-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: onering-client
16
- requirement: &13488540 !ruby/object:Gem::Requirement
16
+ requirement: &15142960 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *13488540
24
+ version_requirements: *15142960
25
25
  description: Base plugins for providing system information via the Onering client
26
26
  utility
27
27
  email: ghetzel@outbrain.com
@@ -32,6 +32,7 @@ files:
32
32
  - lib/facter/onering_properties_openvz.rb
33
33
  - lib/facter/onering_properties_network.rb
34
34
  - lib/facter/onering_properties_virident.rb
35
+ - lib/facter/onering_properties_netstat.rb
35
36
  - lib/facter/onering_properties_services.rb
36
37
  - lib/facter/onering_properties_chef.rb
37
38
  - lib/facter/onering_properties_physical.rb