simple_host_monitoring 1.1.3 → 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
- SHA256:
3
- metadata.gz: ad29af6cc396b701f0466c4f60e1e1417659aafae501d2fa33071b9f4f5f6516
4
- data.tar.gz: eb5dcabfbeb19a656c60cd9919040a78ae1e9baebe0f057a77b87fea7ef4dde7
2
+ SHA1:
3
+ metadata.gz: 4ba993e5a93a0bd30a1f883e9dc298db9a09a886
4
+ data.tar.gz: 276a2f20a0c4aa5a9903ef5bd61951678b1d06cf
5
5
  SHA512:
6
- metadata.gz: e8ea4284223480c9ea6ac6d76286835cdaaf496456c067a80712ba33fdc4315f1eb433077b2ef92a9139698e30d04c2826232e5b06f50b85258676be70c4bb40
7
- data.tar.gz: 1f5ed2593cf5f0ee6f14632d46b7cbc6dc9700af5f36157325f61236a41fbdb8beaca2bae2cd33f34999dcdcc2fcd9f57ac2559ef3b1a33ff268f56dcb7bc65f
6
+ metadata.gz: a00b3474829d5eea7f35b4db9648268b62a7d7fd6d9525deffd824368a1a3c5dfef70e14efa934edaf8ac2ee03b10dfe17d71c1ebf974a31b16481f25a95d7a8
7
+ data.tar.gz: b91e7b6828fb7272806ef572819c1778c29952f63139237d02cf41bb8099149b47031c7232e3cd4b5ceace6182e301a3d7672bcbca5d2ca19e48bb50c8852938
@@ -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://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
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,158 +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 = 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
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,76 +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
- 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
-
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,53 +1,53 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_host_monitoring
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
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: 2021-07-12 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
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
@@ -68,60 +68,60 @@ dependencies:
68
68
  name: sequel
69
69
  requirement: !ruby/object:Gem::Requirement
70
70
  requirements:
71
- - - ">="
71
+ - - "~>"
72
72
  - !ruby/object:Gem::Version
73
73
  version: 4.28.0
74
- - - "~>"
74
+ - - ">="
75
75
  - !ruby/object:Gem::Version
76
76
  version: 4.28.0
77
77
  type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - ">="
81
+ - - "~>"
82
82
  - !ruby/object:Gem::Version
83
83
  version: 4.28.0
84
- - - "~>"
84
+ - - ">="
85
85
  - !ruby/object:Gem::Version
86
86
  version: 4.28.0
87
87
  - !ruby/object:Gem::Dependency
88
88
  name: simple_command_line_parser
89
89
  requirement: !ruby/object:Gem::Requirement
90
90
  requirements:
91
- - - ">="
91
+ - - "~>"
92
92
  - !ruby/object:Gem::Version
93
93
  version: 1.1.2
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: 1.1.2
97
97
  type: :runtime
98
98
  prerelease: false
99
99
  version_requirements: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
103
  version: 1.1.2
104
- - - "~>"
104
+ - - ">="
105
105
  - !ruby/object:Gem::Version
106
106
  version: 1.1.2
107
107
  - !ruby/object:Gem::Dependency
108
108
  name: simple_cloud_logging
109
109
  requirement: !ruby/object:Gem::Requirement
110
110
  requirements:
111
- - - ">="
111
+ - - "~>"
112
112
  - !ruby/object:Gem::Version
113
113
  version: 1.1.23
114
- - - "~>"
114
+ - - ">="
115
115
  - !ruby/object:Gem::Version
116
116
  version: 1.1.23
117
117
  type: :runtime
118
118
  prerelease: false
119
119
  version_requirements: !ruby/object:Gem::Requirement
120
120
  requirements:
121
- - - ">="
121
+ - - "~>"
122
122
  - !ruby/object:Gem::Version
123
123
  version: 1.1.23
124
- - - "~>"
124
+ - - ">="
125
125
  - !ruby/object:Gem::Version
126
126
  version: 1.1.23
127
127
  description: 'THIS GEM IS STILL IN DEVELOPMENT STAGE. Find documentation here: https://github.com/leandrosardi/simple_host_monitoring.'
@@ -155,7 +155,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  - !ruby/object:Gem::Version
156
156
  version: '0'
157
157
  requirements: []
158
- rubygems_version: 3.0.8
158
+ rubyforge_project:
159
+ rubygems_version: 2.4.5.1
159
160
  signing_key:
160
161
  specification_version: 4
161
162
  summary: THIS GEM IS STILL IN DEVELOPMENT STAGE. Track memory, CPU and disk space