simple_host_monitoring 0.0.11 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a64cfa3d62d4bba06a36e7e1ab2d70af099c6f8
4
- data.tar.gz: 956c649ef916638de656f5b9ce86ff221bf1b27f
3
+ metadata.gz: 4ba993e5a93a0bd30a1f883e9dc298db9a09a886
4
+ data.tar.gz: 276a2f20a0c4aa5a9903ef5bd61951678b1d06cf
5
5
  SHA512:
6
- metadata.gz: f929de44841715a326064b0a89b52f85b02afeda5eccfc0305200b1da7321be210e0f9cd49385603e40079a8922a48e863dfcfd39bc6e3def3c0977940937840
7
- data.tar.gz: 3dee7a1c6bbb1ac3201e3dcf5d9d95260228cd379550da5a3cced3f480df45afab69d63bdded6f00fa4d30f45b83c0e98decfd1a03246f633bc22bd4469152fe
6
+ metadata.gz: a00b3474829d5eea7f35b4db9648268b62a7d7fd6d9525deffd824368a1a3c5dfef70e14efa934edaf8ac2ee03b10dfe17d71c1ebf974a31b16481f25a95d7a8
7
+ data.tar.gz: b91e7b6828fb7272806ef572819c1778c29952f63139237d02cf41bb8099149b47031c7232e3cd4b5ceace6182e301a3d7672bcbca5d2ca19e48bb50c8852938
@@ -32,8 +32,8 @@ logger = BlackStack::LocalLoggerFactory.create('./example01.log')
32
32
 
33
33
  #
34
34
  while (true)
35
- url = "https://127.0.0.1:444/api1.4/shm/update.json"
36
- api_key = 'E20CBAE0-A4D4-4161-8812-6D9FE67A2E47'
35
+ url = "https://euler.connectionsphere.com/api1.4/shm/update.json"
36
+ api_key = '290582D4-D00C-4D37-82AF-23043B242647'
37
37
 
38
38
  logger.logs "Flag start time... "
39
39
  start_time = Time.now
data/lib/basehost.rb CHANGED
@@ -7,56 +7,65 @@ include Sys
7
7
  module BlackStack
8
8
 
9
9
  module BaseHost
10
-
10
+
11
11
  # Map the status of this host to the attributes of the class
12
12
  # Returns the hash descriptor of the object
13
13
  def poll()
14
- b_total_memory = `wmic ComputerSystem get TotalPhysicalMemory`.delete('^0-9').to_i
15
- kb_total_memory = b_total_memory / 1024
14
+ b_total_memory = windows_os? ? `wmic ComputerSystem get TotalPhysicalMemory`.delete('^0-9').to_i : `cat /proc/meminfo | grep MemTotal`.delete('^0-9').to_i*1024
15
+ kb_total_memory = b_total_memory / 1024
16
16
  mb_total_memory = kb_total_memory / 1024
17
17
  gb_total_memory = mb_total_memory / 1024
18
-
19
- kb_free_memory = `wmic OS get FreePhysicalMemory`.delete('^0-9').to_i
18
+
19
+ kb_free_memory = windows_os? ? `wmic OS get FreePhysicalMemory`.delete('^0-9').to_i : `cat /proc/meminfo | grep MemFree`.delete('^0-9').to_i
20
20
  mb_free_memory = kb_free_memory / 1024
21
21
  gb_free_memory = mb_free_memory / 1024
22
-
22
+
23
23
  # getting disk free space
24
24
  stat = Sys::Filesystem.stat("/")
25
25
  mb_total_disk = stat.block_size * stat.blocks / 1024 / 1024
26
26
  mb_free_disk = stat.block_size * stat.blocks_available / 1024 / 1024
27
-
27
+
28
28
  # getting public Internet IP
29
29
  #remote_ip = remoteIp()
30
-
30
+
31
31
  # getting server name
32
32
  hostname = Socket.gethostname
33
-
33
+
34
34
  # mapping cpu status
35
- # self.id = BlackStack::SimpleHostMonitoring::host_id
36
- self.cpu_architecture = CPU.architecture.to_s
37
- self.cpu_speed = CPU.freq.to_i
38
- self.cpu_load_average = CPU.load_avg.to_i
39
- self.cpu_model = CPU.model.to_s
40
- self.cpu_type = CPU.cpu_type.to_s
41
- self.cpu_number = CPU.num_cpu.to_i
42
-
43
- # mapping ram status
35
+ # self.id = BlackStack::SimpleHostMonitoring::host_id
36
+ if windows_os?
37
+ self.cpu_architecture = CPU.architecture.to_s
38
+ self.cpu_speed = CPU.freq.to_i
39
+ self.cpu_load_average = CPU.load_avg.to_i
40
+ self.cpu_model = CPU.model.to_s
41
+ self.cpu_type = CPU.cpu_type.to_s
42
+ self.cpu_number = CPU.num_cpu.to_i
43
+ else
44
+ self.cpu_architecture = `lscpu | grep Architecture`.split(':')[1].strip!
45
+ self.cpu_speed = `lscpu | grep "CPU MHz:"`.split(':')[1].strip!.to_f.round
46
+ self.cpu_load_average = Sys::CPU.load_avg.to_s.to_i
47
+ self.cpu_model = `lscpu | grep "Model"`.split(':')[1].strip!
48
+ self.cpu_type = self.cpu_model.split(' ')[0]
49
+ self.cpu_number = `lscpu | grep "^CPU(s):"`.split(':')[1].strip!.to_i
50
+ end
51
+
52
+ # mapping ram status
44
53
  self.mem_total = mb_total_memory.to_i
45
54
  self.mem_free = mb_free_memory.to_i
46
-
55
+
47
56
  # mapping disk status
48
57
  self.disk_total = mb_total_disk.to_i
49
58
  self.disk_free = mb_free_disk.to_i
50
-
59
+
51
60
  # mapping lan attributes
52
61
  self.net_hostname = hostname
53
62
  #self.net_remote_ip = remote_ip.to_s
54
63
  self.net_mac_address = BlackStack::SimpleHostMonitoring.macaddress
55
-
64
+
56
65
  self.to_hash
57
66
  end
58
-
59
- #
67
+
68
+ #
60
69
  def to_hash
61
70
  {
62
71
  # :id => self.id,
@@ -65,7 +74,7 @@ module BlackStack
65
74
  :cpu_load_average => self.cpu_load_average,
66
75
  :cpu_model => self.cpu_model,
67
76
  :cpu_type => self.cpu_type,
68
- :cpu_number => self.cpu_number,
77
+ :cpu_number => self.cpu_number,
69
78
  :mem_total => self.mem_total,
70
79
  :mem_free => self.mem_free,
71
80
  :disk_total => self.disk_total,
@@ -73,10 +82,10 @@ module BlackStack
73
82
  :net_hostname => self.net_hostname,
74
83
  #:net_remote_ip => self.net_remote_ip,
75
84
  :net_mac_address => self.net_mac_address
76
- }
85
+ }
77
86
  end
78
-
79
- #
87
+
88
+ #
80
89
  def self.valid_descriptor?(h)
81
90
  return false if !h.is_a?(Hash)
82
91
  # return false if !h[:id].to_s.guid?
@@ -93,10 +102,10 @@ module BlackStack
93
102
  return false if h[:net_hostname].to_s.size==0
94
103
  #return false if h[:net_remote_ip].to_s.size==0
95
104
  return false if h[:net_mac_address].to_s.size==0
96
- true
105
+ true
97
106
  end
98
-
99
- #
107
+
108
+ #
100
109
  def self.descriptor_validation_details(h)
101
110
  s = ''
102
111
  s += 'Wrong descriptor format. ' if !h.is_a?(Hash)
@@ -116,8 +125,8 @@ module BlackStack
116
125
  s += 'Invalid net_mac_address. ' if h[:net_mac_address].to_s.size==0
117
126
  s
118
127
  end
119
-
120
- #
128
+
129
+ #
121
130
  def parse(h)
122
131
  # self.id = h[:id]
123
132
  self.cpu_architecture = h[:cpu_architecture]
@@ -125,21 +134,25 @@ module BlackStack
125
134
  self.cpu_load_average = h[:cpu_load_average]
126
135
  self.cpu_model = h[:cpu_model]
127
136
  self.cpu_type = h[:cpu_type]
128
- self.cpu_number = h[:cpu_number]
137
+ self.cpu_number = h[:cpu_number]
129
138
  self.mem_total = h[:mem_total]
130
139
  self.mem_free = h[:mem_free]
131
140
  self.disk_total = h[:disk_total]
132
141
  self.disk_free = h[:disk_free]
133
142
  self.net_hostname = h[:net_hostname]
134
143
  #self.net_remote_ip = h[:net_remote_ip]
135
- self.net_mac_address = h[:net_mac_address]
144
+ self.net_mac_address = h[:net_mac_address]
136
145
  end
137
-
138
- #
146
+
147
+ #
139
148
  def push(api_key, url)
140
149
  BlackStack::Netting::api_call( url, {:api_key => api_key}.merge(self.to_hash) )
141
150
  end
142
-
151
+
152
+ def windows_os?
153
+ (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
154
+ end
155
+
143
156
  end # module BaseHost
144
157
 
145
- end # module BlackStack
158
+ end # module BlackStack
data/lib/localhost.rb CHANGED
@@ -47,6 +47,16 @@ module BlackStack
47
47
  h.save
48
48
  end
49
49
 
50
+ #
51
+ def mem_load
52
+ 100.to_f*(self.mem_total.to_f - self.mem_free.to_f) / self.mem_total.to_f
53
+ end
54
+
55
+ #
56
+ def disk_load
57
+ 100.to_f*(self.disk_total.to_f - self.disk_free.to_f) / self.disk_total.to_f
58
+ end
59
+
50
60
  end # class LocalHost
51
61
 
52
62
  end # module BlackStack
@@ -1,7 +1,5 @@
1
- require 'blackstack_commons'
2
1
  require 'simple_command_line_parser'
3
2
  require 'simple_cloud_logging'
4
- #require 'pampa'
5
3
 
6
4
  require 'socket'
7
5
  require 'time'
@@ -47,14 +45,16 @@ module BlackStack
47
45
  # TODO: Esta funcion no retorna la mac address completa
48
46
  # TODO: Validar que no se retorne una macaddress virtual, con todos valores en 0
49
47
  def self.macaddress()
48
+ return `cat /sys/class/net/eth0/address`.upcase.strip.gsub(':', '-') unless BlackStack::RemoteHost.new.windows_os?
49
+
50
50
  s = `ipconfig /all`
51
-
52
- # The standard (IEEE 802) format for printing MAC-48
53
- # => addresses in human-friendly form is six groups
54
- # => of two hexadecimal digits, separated by hyphens
51
+
52
+ # The standard (IEEE 802) format for printing MAC-48
53
+ # => addresses in human-friendly form is six groups
54
+ # => of two hexadecimal digits, separated by hyphens
55
55
  # => - or colons :
56
56
  v = s.scan(/(([A-F0-9]{2}\-){5})([A-F0-9]{2}$)/im)
57
-
57
+
58
58
  if (v.size>0)
59
59
  return v.first.join.to_s
60
60
  else
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_host_monitoring
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leandro Daniel Sardi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-22 00:00:00.000000000 Z
11
+ date: 2021-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: websocket
@@ -54,22 +54,16 @@ dependencies:
54
54
  name: tiny_tds
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
- - - "~>"
58
- - !ruby/object:Gem::Version
59
- version: 1.0.5
60
- - - ">="
57
+ - - '='
61
58
  - !ruby/object:Gem::Version
62
- version: 1.0.5
59
+ version: 0.7.0
63
60
  type: :runtime
64
61
  prerelease: false
65
62
  version_requirements: !ruby/object:Gem::Requirement
66
63
  requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: 1.0.5
70
- - - ">="
64
+ - - '='
71
65
  - !ruby/object:Gem::Version
72
- version: 1.0.5
66
+ version: 0.7.0
73
67
  - !ruby/object:Gem::Dependency
74
68
  name: sequel
75
69
  requirement: !ruby/object:Gem::Requirement
@@ -91,65 +85,45 @@ dependencies:
91
85
  - !ruby/object:Gem::Version
92
86
  version: 4.28.0
93
87
  - !ruby/object:Gem::Dependency
94
- name: blackstack_commons
88
+ name: simple_command_line_parser
95
89
  requirement: !ruby/object:Gem::Requirement
96
90
  requirements:
97
91
  - - "~>"
98
92
  - !ruby/object:Gem::Version
99
- version: 0.0.20
93
+ version: 1.1.2
100
94
  - - ">="
101
95
  - !ruby/object:Gem::Version
102
- version: 0.0.20
96
+ version: 1.1.2
103
97
  type: :runtime
104
98
  prerelease: false
105
99
  version_requirements: !ruby/object:Gem::Requirement
106
100
  requirements:
107
101
  - - "~>"
108
102
  - !ruby/object:Gem::Version
109
- version: 0.0.20
103
+ version: 1.1.2
110
104
  - - ">="
111
105
  - !ruby/object:Gem::Version
112
- version: 0.0.20
106
+ version: 1.1.2
113
107
  - !ruby/object:Gem::Dependency
114
108
  name: simple_cloud_logging
115
109
  requirement: !ruby/object:Gem::Requirement
116
110
  requirements:
117
111
  - - "~>"
118
112
  - !ruby/object:Gem::Version
119
- version: 1.1.16
120
- - - ">="
121
- - !ruby/object:Gem::Version
122
- version: 1.1.16
123
- type: :runtime
124
- prerelease: false
125
- version_requirements: !ruby/object:Gem::Requirement
126
- requirements:
127
- - - "~>"
128
- - !ruby/object:Gem::Version
129
- version: 1.1.16
130
- - - ">="
131
- - !ruby/object:Gem::Version
132
- version: 1.1.16
133
- - !ruby/object:Gem::Dependency
134
- name: simple_command_line_parser
135
- requirement: !ruby/object:Gem::Requirement
136
- requirements:
137
- - - "~>"
138
- - !ruby/object:Gem::Version
139
- version: 1.1.1
113
+ version: 1.1.23
140
114
  - - ">="
141
115
  - !ruby/object:Gem::Version
142
- version: 1.1.1
116
+ version: 1.1.23
143
117
  type: :runtime
144
118
  prerelease: false
145
119
  version_requirements: !ruby/object:Gem::Requirement
146
120
  requirements:
147
121
  - - "~>"
148
122
  - !ruby/object:Gem::Version
149
- version: 1.1.1
123
+ version: 1.1.23
150
124
  - - ">="
151
125
  - !ruby/object:Gem::Version
152
- version: 1.1.1
126
+ version: 1.1.23
153
127
  description: 'THIS GEM IS STILL IN DEVELOPMENT STAGE. Find documentation here: https://github.com/leandrosardi/simple_host_monitoring.'
154
128
  email: leandro.sardi@expandedventure.com
155
129
  executables: []