check_host 0.0.0
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 +7 -0
- data/bin/check_host +11 -0
- data/lib/check_host/check_host_ip.rb +36 -0
- data/lib/check_host/send_mail.rb +26 -0
- data/lib/check_host.rb +9 -0
- data/spec/check_host_ip_spec.rb +45 -0
- data/spec/check_host_spec.rb +12 -0
- data/spec/send_mail_spec.rb +13 -0
- metadata +54 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c448d06ac3895bb4e27358cd5fde364f66e79f3e
|
4
|
+
data.tar.gz: 1e9d6ebf03586bcb831baa09b13b05d6c56c0ac6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0efbd6bb1f23e8f947a98c9e5165a1c897bc89279e3777d73fbfb2cc32775069aac110f452f201e09b7fe952b4e8075aea3203f1e31f099333075cda8f46d0cc
|
7
|
+
data.tar.gz: e5a861d8bd8432fa9a2ca9b3f6355af8c3fe3fb95f0d8883b0202342d51cfb12fc9f970711b32edfa7e0504db3790b958961c7bb67ec60da849086b46b663425
|
data/bin/check_host
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require "check_host/send_mail"
|
2
|
+
|
3
|
+
class CheckHostIp
|
4
|
+
|
5
|
+
attr_accessor :host, :ip
|
6
|
+
|
7
|
+
def initialize(host, ip)
|
8
|
+
@host = host
|
9
|
+
@ip = ip
|
10
|
+
end
|
11
|
+
|
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
|
+
# Sends an email if result? is true
|
26
|
+
# @return Boolean
|
27
|
+
# If result? is true then SendMail
|
28
|
+
def notify
|
29
|
+
if result?
|
30
|
+
SendMail.new
|
31
|
+
true
|
32
|
+
else
|
33
|
+
false
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'mail'
|
2
|
+
|
3
|
+
class SendMail
|
4
|
+
def initialize
|
5
|
+
send
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
def send
|
10
|
+
message
|
11
|
+
end
|
12
|
+
|
13
|
+
def message
|
14
|
+
recipient = 'mike@smswmedia.com'
|
15
|
+
mail = Mail.new do
|
16
|
+
from recipient
|
17
|
+
to recipient
|
18
|
+
subject "Fawazalhokair has changed it's IP address"
|
19
|
+
body ''
|
20
|
+
end
|
21
|
+
|
22
|
+
mail.delivery_method :sendmail
|
23
|
+
mail.deliver
|
24
|
+
`echo 'Email sent'`
|
25
|
+
end
|
26
|
+
end
|
data/lib/check_host.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'check_host/check_host_ip'
|
3
|
+
|
4
|
+
RSpec.describe CheckHostIp, '#initialize' do
|
5
|
+
|
6
|
+
HOST_NAME = 'fawazalhokairfashion.com'
|
7
|
+
HOST_IP = '91.109.13.176'
|
8
|
+
let(:check_host) { CheckHostIp.new(HOST_NAME, HOST_IP)}
|
9
|
+
|
10
|
+
context 'with initialization' do
|
11
|
+
it 'should be an instance of CheckHost' do
|
12
|
+
expect(check_host).to be_a CheckHostIp
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should return host' do
|
16
|
+
expect(check_host.host).to eq HOST_NAME
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should return the result from the host command' do
|
20
|
+
expect(check_host.cmd).to eq "#{HOST_NAME} has address #{HOST_IP}\n"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'with results' do
|
26
|
+
it 'should return no result if IP has not changed' do
|
27
|
+
expect(check_host.result?).to eq false
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should return true if IP has changed' do
|
31
|
+
CHANGED_IP = '8.8.8.8'
|
32
|
+
check_host.ip = CHANGED_IP
|
33
|
+
expect(check_host.result?).to eq true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'with notification' do
|
38
|
+
skip('just skipping so as not to get email notifications every second')
|
39
|
+
# it 'should raise an alert if IP has changed' do
|
40
|
+
# ANOTHER_CHANGED_IP = '9.9.9.9'
|
41
|
+
# check_host.ip = ANOTHER_CHANGED_IP
|
42
|
+
# expect(check_host.notify).to eq true
|
43
|
+
# end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'check_host/send_mail'
|
3
|
+
|
4
|
+
describe 'Send Email' do
|
5
|
+
|
6
|
+
RECP = 'mike@smswmedia.com'
|
7
|
+
|
8
|
+
it 'should notify user' do
|
9
|
+
msg = 'fawazalhokairfashion.com has address 1.2.3.4\n'
|
10
|
+
mail = SendMail.new
|
11
|
+
expect(mail).to be_a SendMail
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: check_host
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Watts
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Check host IP and send a notification email if it has changed
|
14
|
+
email: mike@smswmedia.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- bin/check_host
|
20
|
+
- lib/check_host.rb
|
21
|
+
- lib/check_host/check_host_ip.rb
|
22
|
+
- lib/check_host/send_mail.rb
|
23
|
+
- spec/check_host_ip_spec.rb
|
24
|
+
- spec/check_host_spec.rb
|
25
|
+
- spec/send_mail_spec.rb
|
26
|
+
homepage: http://smswmedia.com
|
27
|
+
licenses:
|
28
|
+
- GPL-3.0
|
29
|
+
metadata: {}
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
requirements: []
|
45
|
+
rubyforge_project:
|
46
|
+
rubygems_version: 2.4.8
|
47
|
+
signing_key:
|
48
|
+
specification_version: 4
|
49
|
+
summary: Notify if host IP has changed
|
50
|
+
test_files:
|
51
|
+
- spec/check_host_ip_spec.rb
|
52
|
+
- spec/send_mail_spec.rb
|
53
|
+
- spec/check_host_spec.rb
|
54
|
+
has_rdoc:
|