simple_host_monitoring 1.1.1 → 1.1.6

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: 8cb8745fb18b771749c088bce363ce79be93d0a0
4
- data.tar.gz: 20ada3d565ef78e033e1e61f6368cef5172a8fa9
3
+ metadata.gz: e473f9c33841dfd3b489c434bae1751a587fec16
4
+ data.tar.gz: 370acdef2777fd6865d3f8f5592a51c0a6d6fa16
5
5
  SHA512:
6
- metadata.gz: c8d938ac4ee0341250d0cb86a8fdf9f84599e2721929ac87afe46c76c2deda7714d1f7bc5827a59e2ec63363e5443c7531473001fc20d8ca52e072c8d22d57a1
7
- data.tar.gz: b4c5d43d87ad812e2bbf97e9f3fb607b03d70853cee05c3a6d014c82886c44522783b975d112e6596a9d64e24ba167089ae3494e5999a3d7369407d7a0855997
6
+ metadata.gz: ae38a1728b7f93b15d413a3f7759758ac41bb2e28f4487cbdefc1040626cd4e087a5fcb136028ca6c92ec522254ca450a7e15260e448febb45c69e5a763aefe5
7
+ data.tar.gz: 20690ba33e9af2a95951c5269a3552db505f3041329e156915be7913b4c0464b8e450fa85c572287747d6acb31f05ebdcb9fc94d715df02475a4cd1713a3802c
@@ -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
@@ -45,14 +45,16 @@ module BlackStack
45
45
  # TODO: Esta funcion no retorna la mac address completa
46
46
  # TODO: Validar que no se retorne una macaddress virtual, con todos valores en 0
47
47
  def self.macaddress()
48
+ return `cat /sys/class/net/eth0/address`.upcase.strip.gsub(':', '-') unless BlackStack::RemoteHost.new.windows_os?
49
+
48
50
  s = `ipconfig /all`
49
-
50
- # The standard (IEEE 802) format for printing MAC-48
51
- # => addresses in human-friendly form is six groups
52
- # => 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
53
55
  # => - or colons :
54
56
  v = s.scan(/(([A-F0-9]{2}\-){5})([A-F0-9]{2}$)/im)
55
-
57
+
56
58
  if (v.size>0)
57
59
  return v.first.join.to_s
58
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: 1.1.1
4
+ version: 1.1.6
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: 2020-01-02 00:00:00.000000000 Z
11
+ date: 2021-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: websocket
@@ -54,20 +54,14 @@ 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
59
  version: 1.0.5
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
66
  version: 1.0.5
73
67
  - !ruby/object:Gem::Dependency