check_host 0.0.0 → 0.0.1
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.
- checksums.yaml +4 -4
- data/lib/check_host.rb +4 -1
- data/lib/check_host/check_host_ip.rb +17 -14
- data/lib/check_host/send_mail.rb +2 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46d50b552dfe87c5da4658c7a60b5e5dd7c7a9e8
|
4
|
+
data.tar.gz: e493e95dded3d92ea715dc6407b7bbce6e52a5fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 409927f6e8a2f408426bf61f92feeda93ebb1cbd43565c382a71edb9143bf89d2e4ac8f843963e751e85ac1b0e5c7b6def0e07bf6bfc0150b0eede6f6c7e17a9
|
7
|
+
data.tar.gz: 2fc591e520b7d5f0aa81ca754a02ee580cc099bdfea57dad88ed9bca904a7bd12d990a1aee40cbd1a412bfcbffd161d016b125a50f669e37f43bf2f8b489fd8d
|
data/lib/check_host.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
require 'check_host/check_host_ip'
|
2
2
|
|
3
3
|
class CheckHost
|
4
|
+
# run
|
5
|
+
# @param: host [String] the host name
|
6
|
+
# @param: ip [String] the host IP address
|
7
|
+
# @return [Boolean] true if notification has taken place, otherwise returns false
|
4
8
|
def self.run(host, ip)
|
5
9
|
c = CheckHostIp.new(host, ip)
|
6
10
|
c.notify
|
7
|
-
true
|
8
11
|
end
|
9
12
|
end
|
@@ -2,29 +2,18 @@ require "check_host/send_mail"
|
|
2
2
|
|
3
3
|
class CheckHostIp
|
4
4
|
|
5
|
+
# @!attribute
|
5
6
|
attr_accessor :host, :ip
|
6
7
|
|
8
|
+
# @param: host (String) The host name
|
9
|
+
# @param: ip (String) The host IP
|
7
10
|
def initialize(host, ip)
|
8
11
|
@host = host
|
9
12
|
@ip = ip
|
10
13
|
end
|
11
14
|
|
12
|
-
# Runs the host cmd and returns just the A record
|
13
|
-
# @return String
|
14
|
-
# example: "fawazalhokairfashion.com has address 91.109.13.176\n"
|
15
|
-
def cmd
|
16
|
-
`host -t A #{host}`
|
17
|
-
end
|
18
|
-
|
19
|
-
# Checks whether a string contains the ip address
|
20
|
-
# @return Boolean
|
21
|
-
def result?
|
22
|
-
!cmd.include? ip
|
23
|
-
end
|
24
|
-
|
25
15
|
# Sends an email if result? is true
|
26
16
|
# @return Boolean
|
27
|
-
# If result? is true then SendMail
|
28
17
|
def notify
|
29
18
|
if result?
|
30
19
|
SendMail.new
|
@@ -33,4 +22,18 @@ class CheckHostIp
|
|
33
22
|
false
|
34
23
|
end
|
35
24
|
end
|
25
|
+
|
26
|
+
private
|
27
|
+
# Runs the host cmd and returns just the A record
|
28
|
+
# example: "fawazalhokairfashion.com has address 91.109.13.176\\n"
|
29
|
+
# @return String
|
30
|
+
def cmd
|
31
|
+
`host -t A #{host}`
|
32
|
+
end
|
33
|
+
|
34
|
+
# Checks whether a string contains the ip address
|
35
|
+
# @return Boolean
|
36
|
+
def result?
|
37
|
+
!cmd.include? ip
|
38
|
+
end
|
36
39
|
end
|
data/lib/check_host/send_mail.rb
CHANGED
@@ -6,10 +6,12 @@ class SendMail
|
|
6
6
|
end
|
7
7
|
|
8
8
|
private
|
9
|
+
# @return [Mail::Message]
|
9
10
|
def send
|
10
11
|
message
|
11
12
|
end
|
12
13
|
|
14
|
+
# @return [Mail::Message]
|
13
15
|
def message
|
14
16
|
recipient = 'mike@smswmedia.com'
|
15
17
|
mail = Mail.new do
|
@@ -21,6 +23,5 @@ class SendMail
|
|
21
23
|
|
22
24
|
mail.delivery_method :sendmail
|
23
25
|
mail.deliver
|
24
|
-
`echo 'Email sent'`
|
25
26
|
end
|
26
27
|
end
|