simple_host_monitoring 1.1.1 → 1.1.3

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
- SHA1:
3
- metadata.gz: 8cb8745fb18b771749c088bce363ce79be93d0a0
4
- data.tar.gz: 20ada3d565ef78e033e1e61f6368cef5172a8fa9
2
+ SHA256:
3
+ metadata.gz: ad29af6cc396b701f0466c4f60e1e1417659aafae501d2fa33071b9f4f5f6516
4
+ data.tar.gz: eb5dcabfbeb19a656c60cd9919040a78ae1e9baebe0f057a77b87fea7ef4dde7
5
5
  SHA512:
6
- metadata.gz: c8d938ac4ee0341250d0cb86a8fdf9f84599e2721929ac87afe46c76c2deda7714d1f7bc5827a59e2ec63363e5443c7531473001fc20d8ca52e072c8d22d57a1
7
- data.tar.gz: b4c5d43d87ad812e2bbf97e9f3fb607b03d70853cee05c3a6d014c82886c44522783b975d112e6596a9d64e24ba167089ae3494e5999a3d7369407d7a0855997
6
+ metadata.gz: e8ea4284223480c9ea6ac6d76286835cdaaf496456c067a80712ba33fdc4315f1eb433077b2ef92a9139698e30d04c2826232e5b06f50b85258676be70c4bb40
7
+ data.tar.gz: 1f5ed2593cf5f0ee6f14632d46b7cbc6dc9700af5f36157325f61236a41fbdb8beaca2bae2cd33f34999dcdcc2fcd9f57ac2559ef3b1a33ff268f56dcb7bc65f
@@ -1,60 +1,60 @@
1
- require_relative '../lib/simple_host_monitoring'
2
-
3
- #
4
- parser = BlackStack::SimpleCommandLineParser.new(
5
- :description => 'This command will launch a SimpleHostMonitoring client that will push the status of the host every X seconds.',
6
- :configuration => [{
7
- :name=>'log',
8
- :mandatory=>false,
9
- :description=>'Write a logfile with the status of this command.',
10
- :type=>BlackStack::SimpleCommandLineParser::BOOL,
11
- :default=>false
12
- },
13
- {
14
- :name=>'log_auto_delete',
15
- :mandatory=>false,
16
- :description=>'Write a logfile with the status of this command.',
17
- :type=>BlackStack::SimpleCommandLineParser::BOOL,
18
- :default=>true
19
- },
20
- {
21
- :name=>'poll_seconds',
22
- :mandatory=>false,
23
- :description=>'How many delay seconds between the starting of a poll cycle and the starting of the next one.',
24
- :type=>BlackStack::SimpleCommandLineParser::INT,
25
- :default=>10
26
- },
27
- ]
28
- )
29
-
30
- #
31
- logger = BlackStack::LocalLoggerFactory.create('./example01.log')
32
-
33
- #
34
- while (true)
35
- url = "https://127.0.0.1:444/api1.4/shm/update.json"
36
- api_key = 'E20CBAE0-A4D4-4161-8812-6D9FE67A2E47'
37
-
38
- logger.logs "Flag start time... "
39
- start_time = Time.now
40
- logger.done
41
-
42
- logger.logs "Poll... "
43
- host = BlackStack::RemoteHost.new
44
- host.poll
45
- logger.done
46
-
47
- logger.logs "Flag end time... "
48
- end_time = Time.now
49
- logger.done
50
-
51
- logger.logs "Push... "
52
- host.push(api_key, url)
53
- logger.done
54
-
55
- logger.logs "Sleep... "
56
- enlapsed_seconds = end_time - start_time
57
- poll_seconds = parser.value('poll_seconds')
58
- sleep( poll_seconds - enlapsed_seconds ) if poll_seconds > enlapsed_seconds
59
- logger.done
60
- end
1
+ require_relative '../lib/simple_host_monitoring'
2
+
3
+ #
4
+ parser = BlackStack::SimpleCommandLineParser.new(
5
+ :description => 'This command will launch a SimpleHostMonitoring client that will push the status of the host every X seconds.',
6
+ :configuration => [{
7
+ :name=>'log',
8
+ :mandatory=>false,
9
+ :description=>'Write a logfile with the status of this command.',
10
+ :type=>BlackStack::SimpleCommandLineParser::BOOL,
11
+ :default=>false
12
+ },
13
+ {
14
+ :name=>'log_auto_delete',
15
+ :mandatory=>false,
16
+ :description=>'Write a logfile with the status of this command.',
17
+ :type=>BlackStack::SimpleCommandLineParser::BOOL,
18
+ :default=>true
19
+ },
20
+ {
21
+ :name=>'poll_seconds',
22
+ :mandatory=>false,
23
+ :description=>'How many delay seconds between the starting of a poll cycle and the starting of the next one.',
24
+ :type=>BlackStack::SimpleCommandLineParser::INT,
25
+ :default=>10
26
+ },
27
+ ]
28
+ )
29
+
30
+ #
31
+ logger = BlackStack::LocalLoggerFactory.create('./example01.log')
32
+
33
+ #
34
+ while (true)
35
+ url = "https://euler.connectionsphere.com/api1.4/shm/update.json"
36
+ api_key = '290582D4-D00C-4D37-82AF-23043B242647'
37
+
38
+ logger.logs "Flag start time... "
39
+ start_time = Time.now
40
+ logger.done
41
+
42
+ logger.logs "Poll... "
43
+ host = BlackStack::RemoteHost.new
44
+ host.poll
45
+ logger.done
46
+
47
+ logger.logs "Flag end time... "
48
+ end_time = Time.now
49
+ logger.done
50
+
51
+ logger.logs "Push... "
52
+ host.push(api_key, url)
53
+ logger.done
54
+
55
+ logger.logs "Sleep... "
56
+ enlapsed_seconds = end_time - start_time
57
+ poll_seconds = parser.value('poll_seconds')
58
+ sleep( poll_seconds - enlapsed_seconds ) if poll_seconds > enlapsed_seconds
59
+ logger.done
60
+ end
data/lib/basehost.rb CHANGED
@@ -1,145 +1,158 @@
1
- require 'open-uri'
2
- require 'sys/filesystem'
3
- require 'sys/cpu'
4
- require 'pp'
5
- include Sys
6
-
7
- module BlackStack
8
-
9
- module BaseHost
10
-
11
- # Map the status of this host to the attributes of the class
12
- # Returns the hash descriptor of the object
13
- def poll()
14
- b_total_memory = `wmic ComputerSystem get TotalPhysicalMemory`.delete('^0-9').to_i
15
- kb_total_memory = b_total_memory / 1024
16
- mb_total_memory = kb_total_memory / 1024
17
- gb_total_memory = mb_total_memory / 1024
18
-
19
- kb_free_memory = `wmic OS get FreePhysicalMemory`.delete('^0-9').to_i
20
- mb_free_memory = kb_free_memory / 1024
21
- gb_free_memory = mb_free_memory / 1024
22
-
23
- # getting disk free space
24
- stat = Sys::Filesystem.stat("/")
25
- mb_total_disk = stat.block_size * stat.blocks / 1024 / 1024
26
- mb_free_disk = stat.block_size * stat.blocks_available / 1024 / 1024
27
-
28
- # getting public Internet IP
29
- #remote_ip = remoteIp()
30
-
31
- # getting server name
32
- hostname = Socket.gethostname
33
-
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
44
- self.mem_total = mb_total_memory.to_i
45
- self.mem_free = mb_free_memory.to_i
46
-
47
- # mapping disk status
48
- self.disk_total = mb_total_disk.to_i
49
- self.disk_free = mb_free_disk.to_i
50
-
51
- # mapping lan attributes
52
- self.net_hostname = hostname
53
- #self.net_remote_ip = remote_ip.to_s
54
- self.net_mac_address = BlackStack::SimpleHostMonitoring.macaddress
55
-
56
- self.to_hash
57
- end
58
-
59
- #
60
- def to_hash
61
- {
62
- # :id => self.id,
63
- :cpu_architecture => self.cpu_architecture,
64
- :cpu_speed => self.cpu_speed,
65
- :cpu_load_average => self.cpu_load_average,
66
- :cpu_model => self.cpu_model,
67
- :cpu_type => self.cpu_type,
68
- :cpu_number => self.cpu_number,
69
- :mem_total => self.mem_total,
70
- :mem_free => self.mem_free,
71
- :disk_total => self.disk_total,
72
- :disk_free => self.disk_free,
73
- :net_hostname => self.net_hostname,
74
- #:net_remote_ip => self.net_remote_ip,
75
- :net_mac_address => self.net_mac_address
76
- }
77
- end
78
-
79
- #
80
- def self.valid_descriptor?(h)
81
- return false if !h.is_a?(Hash)
82
- # return false if !h[:id].to_s.guid?
83
- return false if h[:cpu_architecture].to_s.size==0
84
- return false if !h[:cpu_speed].to_s.fixnum?
85
- return false if !h[:cpu_load_average].to_s.fixnum?
86
- return false if h[:cpu_model].to_s.size==0
87
- return false if h[:cpu_type].to_s.size==0
88
- return false if !h[:cpu_number].to_s.fixnum?
89
- return false if !h[:mem_total].to_s.fixnum?
90
- return false if !h[:mem_free].to_s.fixnum?
91
- return false if !h[:disk_total].to_s.fixnum?
92
- return false if !h[:disk_free].to_s.fixnum?
93
- return false if h[:net_hostname].to_s.size==0
94
- #return false if h[:net_remote_ip].to_s.size==0
95
- return false if h[:net_mac_address].to_s.size==0
96
- true
97
- end
98
-
99
- #
100
- def self.descriptor_validation_details(h)
101
- s = ''
102
- s += 'Wrong descriptor format. ' if !h.is_a?(Hash)
103
- # s += 'Invalid id. ' if !h[:id].to_s.guid?
104
- s += 'Invalid cpu_architecture. ' if h[:cpu_architecture].to_s.size==0
105
- s += 'Invalid cpu_speed. ' if !h[:cpu_speed].to_s.fixnum?
106
- s += 'Invalid cpu_load_average. ' if !h[:cpu_load_average].to_s.fixnum?
107
- s += 'Invalid cpu_model. ' if h[:cpu_model].to_s.size==0
108
- s += 'Invalid cpu_type. ' if h[:cpu_type].to_s.size==0
109
- s += 'Invalid cpu_number. ' if !h[:cpu_number].to_s.fixnum?
110
- s += 'Invalid mem_total. ' if !h[:mem_total].to_s.fixnum?
111
- s += 'Invalid mem_free. ' if !h[:mem_free].to_s.fixnum?
112
- s += 'Invalid disk_total. ' if !h[:disk_total].to_s.fixnum?
113
- s += 'Invalid disk_free. ' if !h[:disk_free].to_s.fixnum?
114
- s += 'Invalid net_hostname. ' if h[:net_hostname].to_s.size==0
115
- #s += 'Invalid :net_remote_ip. ' if h[:net_remote_ip].to_s.size==0
116
- s += 'Invalid net_mac_address. ' if h[:net_mac_address].to_s.size==0
117
- s
118
- end
119
-
120
- #
121
- def parse(h)
122
- # self.id = h[:id]
123
- self.cpu_architecture = h[:cpu_architecture]
124
- self.cpu_speed = h[:cpu_speed]
125
- self.cpu_load_average = h[:cpu_load_average]
126
- self.cpu_model = h[:cpu_model]
127
- self.cpu_type = h[:cpu_type]
128
- self.cpu_number = h[:cpu_number]
129
- self.mem_total = h[:mem_total]
130
- self.mem_free = h[:mem_free]
131
- self.disk_total = h[:disk_total]
132
- self.disk_free = h[:disk_free]
133
- self.net_hostname = h[:net_hostname]
134
- #self.net_remote_ip = h[:net_remote_ip]
135
- self.net_mac_address = h[:net_mac_address]
136
- end
137
-
138
- #
139
- def push(api_key, url)
140
- BlackStack::Netting::api_call( url, {:api_key => api_key}.merge(self.to_hash) )
141
- end
142
-
143
- end # module BaseHost
144
-
145
- end # module BlackStack
1
+ require 'open-uri'
2
+ require 'sys/filesystem'
3
+ require 'sys/cpu'
4
+ require 'pp'
5
+ include Sys
6
+
7
+ module BlackStack
8
+
9
+ module BaseHost
10
+
11
+ # Map the status of this host to the attributes of the class
12
+ # Returns the hash descriptor of the object
13
+ def poll()
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
+ mb_total_memory = kb_total_memory / 1024
17
+ gb_total_memory = mb_total_memory / 1024
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
+ mb_free_memory = kb_free_memory / 1024
21
+ gb_free_memory = mb_free_memory / 1024
22
+
23
+ # getting disk free space
24
+ stat = Sys::Filesystem.stat("/")
25
+ mb_total_disk = stat.block_size * stat.blocks / 1024 / 1024
26
+ mb_free_disk = stat.block_size * stat.blocks_available / 1024 / 1024
27
+
28
+ # getting public Internet IP
29
+ #remote_ip = remoteIp()
30
+
31
+ # getting server name
32
+ hostname = Socket.gethostname
33
+
34
+ # mapping cpu 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
53
+ self.mem_total = mb_total_memory.to_i
54
+ self.mem_free = mb_free_memory.to_i
55
+
56
+ # mapping disk status
57
+ self.disk_total = mb_total_disk.to_i
58
+ self.disk_free = mb_free_disk.to_i
59
+
60
+ # mapping lan attributes
61
+ self.net_hostname = hostname
62
+ #self.net_remote_ip = remote_ip.to_s
63
+ self.net_mac_address = BlackStack::SimpleHostMonitoring.macaddress
64
+
65
+ self.to_hash
66
+ end
67
+
68
+ #
69
+ def to_hash
70
+ {
71
+ # :id => self.id,
72
+ :cpu_architecture => self.cpu_architecture,
73
+ :cpu_speed => self.cpu_speed,
74
+ :cpu_load_average => self.cpu_load_average,
75
+ :cpu_model => self.cpu_model,
76
+ :cpu_type => self.cpu_type,
77
+ :cpu_number => self.cpu_number,
78
+ :mem_total => self.mem_total,
79
+ :mem_free => self.mem_free,
80
+ :disk_total => self.disk_total,
81
+ :disk_free => self.disk_free,
82
+ :net_hostname => self.net_hostname,
83
+ #:net_remote_ip => self.net_remote_ip,
84
+ :net_mac_address => self.net_mac_address
85
+ }
86
+ end
87
+
88
+ #
89
+ def self.valid_descriptor?(h)
90
+ return false if !h.is_a?(Hash)
91
+ # return false if !h[:id].to_s.guid?
92
+ return false if h[:cpu_architecture].to_s.size==0
93
+ return false if !h[:cpu_speed].to_s.fixnum?
94
+ return false if !h[:cpu_load_average].to_s.fixnum?
95
+ return false if h[:cpu_model].to_s.size==0
96
+ return false if h[:cpu_type].to_s.size==0
97
+ return false if !h[:cpu_number].to_s.fixnum?
98
+ return false if !h[:mem_total].to_s.fixnum?
99
+ return false if !h[:mem_free].to_s.fixnum?
100
+ return false if !h[:disk_total].to_s.fixnum?
101
+ return false if !h[:disk_free].to_s.fixnum?
102
+ return false if h[:net_hostname].to_s.size==0
103
+ #return false if h[:net_remote_ip].to_s.size==0
104
+ return false if h[:net_mac_address].to_s.size==0
105
+ true
106
+ end
107
+
108
+ #
109
+ def self.descriptor_validation_details(h)
110
+ s = ''
111
+ s += 'Wrong descriptor format. ' if !h.is_a?(Hash)
112
+ # s += 'Invalid id. ' if !h[:id].to_s.guid?
113
+ s += 'Invalid cpu_architecture. ' if h[:cpu_architecture].to_s.size==0
114
+ s += 'Invalid cpu_speed. ' if !h[:cpu_speed].to_s.fixnum?
115
+ s += 'Invalid cpu_load_average. ' if !h[:cpu_load_average].to_s.fixnum?
116
+ s += 'Invalid cpu_model. ' if h[:cpu_model].to_s.size==0
117
+ s += 'Invalid cpu_type. ' if h[:cpu_type].to_s.size==0
118
+ s += 'Invalid cpu_number. ' if !h[:cpu_number].to_s.fixnum?
119
+ s += 'Invalid mem_total. ' if !h[:mem_total].to_s.fixnum?
120
+ s += 'Invalid mem_free. ' if !h[:mem_free].to_s.fixnum?
121
+ s += 'Invalid disk_total. ' if !h[:disk_total].to_s.fixnum?
122
+ s += 'Invalid disk_free. ' if !h[:disk_free].to_s.fixnum?
123
+ s += 'Invalid net_hostname. ' if h[:net_hostname].to_s.size==0
124
+ #s += 'Invalid :net_remote_ip. ' if h[:net_remote_ip].to_s.size==0
125
+ s += 'Invalid net_mac_address. ' if h[:net_mac_address].to_s.size==0
126
+ s
127
+ end
128
+
129
+ #
130
+ def parse(h)
131
+ # self.id = h[:id]
132
+ self.cpu_architecture = h[:cpu_architecture]
133
+ self.cpu_speed = h[:cpu_speed]
134
+ self.cpu_load_average = h[:cpu_load_average]
135
+ self.cpu_model = h[:cpu_model]
136
+ self.cpu_type = h[:cpu_type]
137
+ self.cpu_number = h[:cpu_number]
138
+ self.mem_total = h[:mem_total]
139
+ self.mem_free = h[:mem_free]
140
+ self.disk_total = h[:disk_total]
141
+ self.disk_free = h[:disk_free]
142
+ self.net_hostname = h[:net_hostname]
143
+ #self.net_remote_ip = h[:net_remote_ip]
144
+ self.net_mac_address = h[:net_mac_address]
145
+ end
146
+
147
+ #
148
+ def push(api_key, url)
149
+ BlackStack::Netting::api_call( url, {:api_key => api_key}.merge(self.to_hash) )
150
+ end
151
+
152
+ def windows_os?
153
+ (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
154
+ end
155
+
156
+ end # module BaseHost
157
+
158
+ end # module BlackStack
data/lib/localhost.rb CHANGED
@@ -1,62 +1,62 @@
1
- require_relative './basehost'
2
- require_relative './localhosthistory'
3
-
4
- module BlackStack
5
-
6
- class LocalHost < Sequel::Model(:host)
7
- include BaseHost
8
- LocalHost.dataset = LocalHost.dataset.disable_insert_output
9
-
10
- #
11
- def parse(h)
12
- #self.id = h[:id]
13
- self.cpu_architecture = h[:cpu_architecture]
14
- self.cpu_speed = h[:cpu_speed]
15
- self.cpu_load_average = h[:cpu_load_average]
16
- self.cpu_model = h[:cpu_model]
17
- self.cpu_type = h[:cpu_type]
18
- self.cpu_number = h[:cpu_number]
19
- self.mem_total = h[:mem_total]
20
- self.mem_free = h[:mem_free]
21
- self.disk_total = h[:disk_total]
22
- self.disk_free = h[:disk_free]
23
- self.net_hostname = h[:net_hostname]
24
- #self.net_remote_ip = h[:net_remote_ip]
25
- self.net_mac_address = h[:net_mac_address]
26
- end
27
-
28
- #
29
- def track
30
- h = LocalHostHistory.new
31
- h.id = guid()
32
- h.id_host = self.id
33
- h.create_time = now()
34
- h.cpu_architecture = self.cpu_architecture
35
- h.cpu_speed = self.cpu_speed
36
- h.cpu_load_average = self.cpu_load_average
37
- h.cpu_model = self.cpu_model
38
- h.cpu_type = self.cpu_type
39
- h.cpu_number = self.cpu_number
40
- h.mem_total = self.mem_total
41
- h.mem_free = self.mem_free
42
- h.disk_total = self.disk_total
43
- h.disk_free = self.disk_free
44
- h.net_hostname = self.net_hostname
45
- h.net_remote_ip = self.net_remote_ip
46
- h.net_mac_address = self.net_mac_address
47
- h.save
48
- end
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
-
60
- end # class LocalHost
61
-
62
- end # module BlackStack
1
+ require_relative './basehost'
2
+ require_relative './localhosthistory'
3
+
4
+ module BlackStack
5
+
6
+ class LocalHost < Sequel::Model(:host)
7
+ include BaseHost
8
+ LocalHost.dataset = LocalHost.dataset.disable_insert_output
9
+
10
+ #
11
+ def parse(h)
12
+ #self.id = h[:id]
13
+ self.cpu_architecture = h[:cpu_architecture]
14
+ self.cpu_speed = h[:cpu_speed]
15
+ self.cpu_load_average = h[:cpu_load_average]
16
+ self.cpu_model = h[:cpu_model]
17
+ self.cpu_type = h[:cpu_type]
18
+ self.cpu_number = h[:cpu_number]
19
+ self.mem_total = h[:mem_total]
20
+ self.mem_free = h[:mem_free]
21
+ self.disk_total = h[:disk_total]
22
+ self.disk_free = h[:disk_free]
23
+ self.net_hostname = h[:net_hostname]
24
+ #self.net_remote_ip = h[:net_remote_ip]
25
+ self.net_mac_address = h[:net_mac_address]
26
+ end
27
+
28
+ #
29
+ def track
30
+ h = LocalHostHistory.new
31
+ h.id = guid()
32
+ h.id_host = self.id
33
+ h.create_time = now()
34
+ h.cpu_architecture = self.cpu_architecture
35
+ h.cpu_speed = self.cpu_speed
36
+ h.cpu_load_average = self.cpu_load_average
37
+ h.cpu_model = self.cpu_model
38
+ h.cpu_type = self.cpu_type
39
+ h.cpu_number = self.cpu_number
40
+ h.mem_total = self.mem_total
41
+ h.mem_free = self.mem_free
42
+ h.disk_total = self.disk_total
43
+ h.disk_free = self.disk_free
44
+ h.net_hostname = self.net_hostname
45
+ h.net_remote_ip = self.net_remote_ip
46
+ h.net_mac_address = self.net_mac_address
47
+ h.save
48
+ end
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
+
60
+ end # class LocalHost
61
+
62
+ end # module BlackStack
@@ -1,10 +1,10 @@
1
- require_relative './basehost'
2
-
3
- module BlackStack
4
-
5
- class LocalHostHistory < Sequel::Model(:hosthistory)
6
- LocalHostHistory.dataset = LocalHostHistory.dataset.disable_insert_output
7
-
8
- end # class LocalHostHistory
9
-
10
- end # module BlackStack
1
+ require_relative './basehost'
2
+
3
+ module BlackStack
4
+
5
+ class LocalHostHistory < Sequel::Model(:hosthistory)
6
+ LocalHostHistory.dataset = LocalHostHistory.dataset.disable_insert_output
7
+
8
+ end # class LocalHostHistory
9
+
10
+ end # module BlackStack
data/lib/remotehost.rb CHANGED
@@ -1,10 +1,10 @@
1
- require_relative './basehost'
2
-
3
- module BlackStack
4
-
5
- class RemoteHost
6
- attr_accessor :cpu_architecture, :cpu_speed, :cpu_load_average, :cpu_model, :cpu_type, :cpu_number, :mem_total, :mem_free, :disk_total, :disk_free, :net_hostname, :net_remote_ip, :net_mac_address
7
- include BaseHost
8
- end # class RemoteHost
9
-
10
- end # module BlackStack
1
+ require_relative './basehost'
2
+
3
+ module BlackStack
4
+
5
+ class RemoteHost
6
+ attr_accessor :cpu_architecture, :cpu_speed, :cpu_load_average, :cpu_model, :cpu_type, :cpu_number, :mem_total, :mem_free, :disk_total, :disk_free, :net_hostname, :net_remote_ip, :net_mac_address
7
+ include BaseHost
8
+ end # class RemoteHost
9
+
10
+ end # module BlackStack
@@ -1,74 +1,76 @@
1
- require 'simple_command_line_parser'
2
- require 'simple_cloud_logging'
3
-
4
- require 'socket'
5
- require 'time'
6
- require 'uri'
7
- require 'net/http'
8
- require 'json'
9
- require 'openssl'
10
- require 'tiny_tds'
11
- require 'sequel'
12
-
13
- require_relative './basehost'
14
- require_relative './remotehost'
15
- #require_relative './localhost'
16
-
17
- module BlackStack
18
-
19
- module SimpleHostMonitoring
20
-
21
- # get the unique host id from the file ./host_id.data
22
- # if the file does not exists, it will ask the API for a GUID and create the file
23
- HOST_ID_FILENAME = './host_id.data'
24
-
25
- =begin # derepcated
26
- @@host_id = nil
27
- def self.reset_host_id
28
- @@host_id = BlackStack::Pampa::get_guid
29
- File.open(HOST_ID_FILENAME, 'w') {|f| f.write(@@host_id) }
30
- @@host_id
31
- end
32
- def self.host_id
33
- if @@host_id.nil?
34
- if File.file?(HOST_ID_FILENAME)
35
- @@host_id = File.read(HOST_ID_FILENAME)
36
- else
37
- @@host_id = self.reset_host_id
38
- end
39
- end # !@@host_id.nil?
40
- @@host_id = self.reset_host_id if !@@host_id.guid?
41
- @@host_id
42
- end
43
- =end
44
- # This function works in windows only
45
- # TODO: Esta funcion no retorna la mac address completa
46
- # TODO: Validar que no se retorne una macaddress virtual, con todos valores en 0
47
- def self.macaddress()
48
- 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
53
- # => - or colons :
54
- v = s.scan(/(([A-F0-9]{2}\-){5})([A-F0-9]{2}$)/im)
55
-
56
- if (v.size>0)
57
- return v.first.join.to_s
58
- else
59
- return nil
60
- end
61
- end
62
-
63
- #
64
- def self.require_db_classes()
65
- # You have to load all the Sinatra classes after connect the database.
66
- require_relative '../lib/localhost.rb'
67
- require_relative '../lib/localhosthistory.rb'
68
- end
69
-
70
- end # module SimpleHostMonitoring
71
-
72
- end # module BlackStack
73
-
74
-
1
+ require 'simple_command_line_parser'
2
+ require 'simple_cloud_logging'
3
+
4
+ require 'socket'
5
+ require 'time'
6
+ require 'uri'
7
+ require 'net/http'
8
+ require 'json'
9
+ require 'openssl'
10
+ require 'tiny_tds'
11
+ require 'sequel'
12
+
13
+ require_relative './basehost'
14
+ require_relative './remotehost'
15
+ #require_relative './localhost'
16
+
17
+ module BlackStack
18
+
19
+ module SimpleHostMonitoring
20
+
21
+ # get the unique host id from the file ./host_id.data
22
+ # if the file does not exists, it will ask the API for a GUID and create the file
23
+ HOST_ID_FILENAME = './host_id.data'
24
+
25
+ =begin # derepcated
26
+ @@host_id = nil
27
+ def self.reset_host_id
28
+ @@host_id = BlackStack::Pampa::get_guid
29
+ File.open(HOST_ID_FILENAME, 'w') {|f| f.write(@@host_id) }
30
+ @@host_id
31
+ end
32
+ def self.host_id
33
+ if @@host_id.nil?
34
+ if File.file?(HOST_ID_FILENAME)
35
+ @@host_id = File.read(HOST_ID_FILENAME)
36
+ else
37
+ @@host_id = self.reset_host_id
38
+ end
39
+ end # !@@host_id.nil?
40
+ @@host_id = self.reset_host_id if !@@host_id.guid?
41
+ @@host_id
42
+ end
43
+ =end
44
+ # This function works in windows only
45
+ # TODO: Esta funcion no retorna la mac address completa
46
+ # TODO: Validar que no se retorne una macaddress virtual, con todos valores en 0
47
+ def self.macaddress()
48
+ return `cat /sys/class/net/eth0/address`.upcase.strip.gsub(':', '-') unless BlackStack::RemoteHost.new.windows_os?
49
+
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
55
+ # => - or colons :
56
+ v = s.scan(/(([A-F0-9]{2}\-){5})([A-F0-9]{2}$)/im)
57
+
58
+ if (v.size>0)
59
+ return v.first.join.to_s
60
+ else
61
+ return nil
62
+ end
63
+ end
64
+
65
+ #
66
+ def self.require_db_classes()
67
+ # You have to load all the Sinatra classes after connect the database.
68
+ require_relative '../lib/localhost.rb'
69
+ require_relative '../lib/localhosthistory.rb'
70
+ end
71
+
72
+ end # module SimpleHostMonitoring
73
+
74
+ end # module BlackStack
75
+
76
+
metadata CHANGED
@@ -1,133 +1,127 @@
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.3
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-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: websocket
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.2.8
20
- - - ">="
20
+ - - "~>"
21
21
  - !ruby/object:Gem::Version
22
22
  version: 1.2.8
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - "~>"
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: 1.2.8
30
- - - ">="
30
+ - - "~>"
31
31
  - !ruby/object:Gem::Version
32
32
  version: 1.2.8
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: json
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "~>"
37
+ - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: 1.8.1
40
- - - ">="
40
+ - - "~>"
41
41
  - !ruby/object:Gem::Version
42
42
  version: 1.8.1
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - "~>"
47
+ - - ">="
48
48
  - !ruby/object:Gem::Version
49
49
  version: 1.8.1
50
- - - ">="
50
+ - - "~>"
51
51
  - !ruby/object:Gem::Version
52
52
  version: 1.8.1
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: tiny_tds
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
- - - "~>"
57
+ - - '='
58
58
  - !ruby/object:Gem::Version
59
- version: 1.0.5
60
- - - ">="
61
- - !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
- - - "~>"
64
+ - - '='
68
65
  - !ruby/object:Gem::Version
69
- version: 1.0.5
70
- - - ">="
71
- - !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
76
70
  requirements:
77
- - - "~>"
71
+ - - ">="
78
72
  - !ruby/object:Gem::Version
79
73
  version: 4.28.0
80
- - - ">="
74
+ - - "~>"
81
75
  - !ruby/object:Gem::Version
82
76
  version: 4.28.0
83
77
  type: :runtime
84
78
  prerelease: false
85
79
  version_requirements: !ruby/object:Gem::Requirement
86
80
  requirements:
87
- - - "~>"
81
+ - - ">="
88
82
  - !ruby/object:Gem::Version
89
83
  version: 4.28.0
90
- - - ">="
84
+ - - "~>"
91
85
  - !ruby/object:Gem::Version
92
86
  version: 4.28.0
93
87
  - !ruby/object:Gem::Dependency
94
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
93
  version: 1.1.2
100
- - - ">="
94
+ - - "~>"
101
95
  - !ruby/object:Gem::Version
102
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
103
  version: 1.1.2
110
- - - ">="
104
+ - - "~>"
111
105
  - !ruby/object:Gem::Version
112
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
113
  version: 1.1.23
120
- - - ">="
114
+ - - "~>"
121
115
  - !ruby/object:Gem::Version
122
116
  version: 1.1.23
123
117
  type: :runtime
124
118
  prerelease: false
125
119
  version_requirements: !ruby/object:Gem::Requirement
126
120
  requirements:
127
- - - "~>"
121
+ - - ">="
128
122
  - !ruby/object:Gem::Version
129
123
  version: 1.1.23
130
- - - ">="
124
+ - - "~>"
131
125
  - !ruby/object:Gem::Version
132
126
  version: 1.1.23
133
127
  description: 'THIS GEM IS STILL IN DEVELOPMENT STAGE. Find documentation here: https://github.com/leandrosardi/simple_host_monitoring.'
@@ -161,8 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
155
  - !ruby/object:Gem::Version
162
156
  version: '0'
163
157
  requirements: []
164
- rubyforge_project:
165
- rubygems_version: 2.4.5.1
158
+ rubygems_version: 3.0.8
166
159
  signing_key:
167
160
  specification_version: 4
168
161
  summary: THIS GEM IS STILL IN DEVELOPMENT STAGE. Track memory, CPU and disk space