mtr_monitor 0.17.4 → 0.18.0

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: 66793c37ff370c8719a1df787d8951b8295dcac2
4
- data.tar.gz: 0e657330ea76728cea3ba824c8f854af826cbc6b
3
+ metadata.gz: a26972975a867e9e8a9510dfd32b4e24991e6c85
4
+ data.tar.gz: dea7489cce159ab1ed20271d726902b362d9f53f
5
5
  SHA512:
6
- metadata.gz: 151e88fbafb466e30a209ccd3a071136c12ddfba2efcbef21aa1593e0ec7a4635515d57ea9508bd5a33679773ea82763bf833e8d4b2f071ab3c4228cce204ab4
7
- data.tar.gz: 4b54e7ccfe1d01a63a4863bf72573f09736a68aeaa9346f5254bf7ab8371d93bb47153408b36084094ffc7e46b5f4397cedfca12a142ad3c1532767187118ca5
6
+ metadata.gz: 8c6d4c4f74ef30563a2892a0ce89b5376bf4bf13e550ea72d85081585ecf54613b1c42cc3484afd66397bf469e077e550ce655c3403f872fc251c8410c54c474
7
+ data.tar.gz: d758aca42f697617530f62c0433b556109aea48ba06b5744da05945aecb8e7018dec98c9ca8b82bc5d8dfa4752e69397810b3d230e3cb2346d38603e4b4dca2a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mtr_monitor (0.17.4)
4
+ mtr_monitor (0.18.0)
5
5
  logdna
6
6
  rt-watchman (~> 0.10.0)
7
7
 
data/lib/mtr_monitor.rb CHANGED
@@ -23,7 +23,7 @@ module MtrMonitor
23
23
  # MTR Options: Options to pass to the mtr command line tool.
24
24
  #
25
25
 
26
- REPORTS_PATH = "/var/log/mtr"
26
+ LOCAL_REPORTS_DIR = "/var/log/mtr"
27
27
 
28
28
  class Report
29
29
  attr_reader :log_path
@@ -43,30 +43,44 @@ module MtrMonitor
43
43
  @dig_ip_address = dig_ip_address
44
44
  @logger = logger || Logger.new(STDOUT)
45
45
  @logdna = Logdna::Ruby.new(logdna_ingestion_key,
46
- :ip => @host_ip_address,
47
- :app => "MTR monitor",
48
- :meta => { :route => @name },
46
+ :ip => @host_ip_address,
47
+ :app => "MTR monitor",
48
+ :meta => {
49
+ :route => @name,
50
+ :s3 => s3_url
51
+ },
49
52
  :level => "DEBUG")
53
+ end
50
54
 
51
- path = "#{@name}/#{Time.now.strftime("%Y-%m-%d")}/#{@host_ip_address.gsub(".", "-")}/#{Time.now.utc.strftime("%H-%M")}.log"
55
+ def s3_url
56
+ "https://s3.eu-central-1.amazonaws.com/#{@bucket}/#{path}"
57
+ end
52
58
 
53
- @log_path = "#{MtrMonitor::REPORTS_PATH}/#{path.gsub("/", "-")}"
54
- @s3_path = "s3://#{@s3_bucket}/#{path}"
59
+ def s3_uri
60
+ "s3://#{@s3_bucket}/#{path}"
61
+ end
62
+
63
+ def local_log_path
64
+ "#{MtrMonitor::LOCAL_REPORTS_DIR}/#{path.gsub("/", "-")}"
65
+ end
66
+
67
+ def path
68
+ "#{@name}/#{Time.now.strftime("%Y-%m-%d")}/#{@host_ip_address.gsub(".", "-")}/#{Time.now.utc.strftime("%H-%M")}.log"
55
69
  end
56
70
 
57
71
  def generate
58
- logger.info "Local Path: #{@log_path}"
59
- logger.info "S3 Path: #{@s3_path}"
72
+ logger.info "Local Path: #{local_log_path}"
73
+ logger.info "S3 URI: #{s3_uri}"
60
74
 
61
75
  generate_local_report
62
76
  upload_to_s3
63
77
  emit_provider_to_logdna
64
78
 
65
- MtrMonitor::Metrics.submit(@log_path, @hostname, @name, @logger)
79
+ MtrMonitor::Metrics.submit(local_log_path, @hostname, @name, @logger)
66
80
  end
67
81
 
68
82
  def emit_provider_to_logdna
69
- mtr_log = File.read(@log_path)
83
+ mtr_log = File.read(local_log_path)
70
84
 
71
85
  if mtr_log.include?("telia.net")
72
86
  telia
@@ -80,17 +94,17 @@ module MtrMonitor
80
94
  end
81
95
 
82
96
  def telia
83
- @logdna.log("Telia network provider")
97
+ @logdna.log("Telia")
84
98
  @logger.info("Network provider: Telia -- Emitted to LogDNA")
85
99
  end
86
100
 
87
101
  def gtt
88
- @logdna.log("GTT network provider")
102
+ @logdna.log("GTT")
89
103
  @logger.info("Network provider: GTT -- Emitted to LogDNA")
90
104
  end
91
105
 
92
106
  def ntt
93
- @logdna.log("NTT network provider")
107
+ @logdna.log("NTT")
94
108
  @logger.info("Network provider: NTT -- Emitted to LogDNA")
95
109
  end
96
110
 
@@ -100,19 +114,22 @@ module MtrMonitor
100
114
  end
101
115
 
102
116
  def generate_local_report
103
- destination = @dig_ip_address ? dig : @domain
104
-
105
117
  run %Q(sudo mkdir -p /var/log/mtr)
106
- run %Q(sudo sh -c 'echo "Name: #{@name}" >> #{@log_path}')
107
- run %Q(sudo sh -c 'echo "Domain: #{@domain}" >> #{@log_path}')
108
- run %Q(sudo sh -c 'echo "Source IP: #{@host_ip_address}" >> #{@log_path}')
109
- run %Q(sudo sh -c 'echo "Target IP: #{destination}" >> #{@log_path}')
110
- run %Q(sudo sh -c 'echo "---------------------------------------" >> #{@log_path}')
111
- run %Q(sudo sh -c 'mtr --report --report-wide #{@mtr_options} #{destination} >> #{@log_path}')
118
+ run %Q(sudo sh -c 'echo "Version: #{MtrMonitor::VERSION}" >> #{local_log_path}')
119
+ run %Q(sudo sh -c 'echo "Name: #{@name}" >> #{local_log_path}')
120
+ run %Q(sudo sh -c 'echo "Domain: #{@domain}" >> #{local_log_path}')
121
+ run %Q(sudo sh -c 'echo "Source IP: #{@host_ip_address}" >> #{local_log_path}')
122
+ run %Q(sudo sh -c 'echo "Target IP: #{destination}" >> #{local_log_path}')
123
+ run %Q(sudo sh -c 'echo "---------------------------------------" >> #{local_log_path}')
124
+ run %Q(sudo sh -c 'mtr --report --report-wide #{@mtr_options} #{destination} >> #{local_log_path}')
125
+ end
126
+
127
+ def destination
128
+ @dig_ip_address ? dig : @domain
112
129
  end
113
130
 
114
131
  def upload_to_s3
115
- run %Q(AWS_ACCESS_KEY_ID='#{@aws_access_key_id}' AWS_SECRET_ACCESS_KEY='#{@aws_secret_access_key}' aws s3 cp #{@log_path} #{@s3_path})
132
+ run %Q(AWS_ACCESS_KEY_ID='#{@aws_access_key_id}' AWS_SECRET_ACCESS_KEY='#{@aws_secret_access_key}' aws s3 cp #{local_log_path} #{s3_uri})
116
133
  end
117
134
 
118
135
  def dig
@@ -21,7 +21,7 @@ module MtrMonitor
21
21
  end
22
22
 
23
23
  def self.all_reports
24
- Dir.glob("#{MtrMonitor::REPORTS_PATH}/*")
24
+ Dir.glob("#{MtrMonitor::LOCAL_REPORTS_DIR}/*")
25
25
  end
26
26
 
27
27
  end
@@ -1,3 +1,3 @@
1
1
  module MtrMonitor
2
- VERSION = "0.17.4"
2
+ VERSION = "0.18.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mtr_monitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.4
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - RenderedText DevOps Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-10 00:00:00.000000000 Z
11
+ date: 2018-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logdna