insta-monitis 0.1.1 → 0.1.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 676f293bd9d7373fd225bc62409f7e753491cb3e
4
- data.tar.gz: 09049019e014cd2c323e8ed2faaf1eb0b6328627
3
+ metadata.gz: 0b4c610009584b9c42d128e9c367db0bb87da205
4
+ data.tar.gz: 42b12eb535298f050122f6979ab53c221feb98bb
5
5
  SHA512:
6
- metadata.gz: 0632875a0ed47c4ef93009f8097182b0a71f11ca38e09f6e4f60520a25fb3ba32e8447b84b28fdac830a8cf50cd92d00c1c6732fc523eb1c26caa243d6a0c376
7
- data.tar.gz: 1009d8c96c288d30c456631412f99e4724d7e55b05a8256df0d02037fd17ee932b96e6368db06f4643bd1c2aea8f843362679ff1e9df28f60dcdb2d83edab07d
6
+ metadata.gz: 7b33ef7801ec5f7869c514aa83e976d32fd5490a13f2318597f41c60d941697a5a44fde4ac349141ef5a478f9b0ab1fb076f974736817ccef34a238b4dfde5bf
7
+ data.tar.gz: 8a271f08d4586195f8e4f652e4442790c54721d37d54aba298321e51faa4d1058ec6d592b74d2e86940437937557ed9e66fe98a6243819a7683db45cd7363476
data/README.md CHANGED
@@ -151,6 +151,26 @@ Options:
151
151
  -t, [--tag=TAG] # Tag of test(s)
152
152
  ```
153
153
 
154
+
155
+ Report:
156
+ ```ruby
157
+ ~> insta-monitis report http -i 176633 -d 2
158
+ Issuing API requests for 2015-07-24..
159
+ Issuing API requests for 2015-07-23..
160
+ Issuing API requests for 2015-07-22..
161
+
162
+ ~> insta-monitis report
163
+ Commands:
164
+ insta-monitis report help [COMMAND] # Describe subcommands or one specific subcommand
165
+ insta-monitis report http --[ID]=[N] --[DAYS]=[N] # Generate report for given http test
166
+
167
+ Options:
168
+ -i, [--id=N] # Id of test
169
+ -d, [--days=N] # How many days
170
+ # Default: 150
171
+ ```
172
+ The report will create a .csv file in the HOME directory of the current user.
173
+
154
174
  ## Development
155
175
 
156
176
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -8,7 +8,7 @@ module InstaMonitis
8
8
  class Api
9
9
  @@host = 'https://api.monitis.com'
10
10
  @@prefix = '/api'
11
- @@version = 'version=3'
11
+ @@version = 'version=2'
12
12
 
13
13
  def initialize opts={}
14
14
  @key = opts["key"]
@@ -1,4 +1,6 @@
1
1
  require 'uri'
2
+ require 'date'
3
+ require 'csv'
2
4
  require 'insta-monitis/userinput'
3
5
 
4
6
  module InstaMonitis
@@ -49,6 +51,18 @@ module InstaMonitis
49
51
  end
50
52
  end
51
53
  end
54
+
55
+ def search_http_quiet param
56
+ unless param['id'].nil?
57
+ return dump("testinfo&testId=#{param['id']}")
58
+ else
59
+ unless param['tag'].nil?
60
+ return dump("tagtests&tag=#{param['tag']}")
61
+ else
62
+ return search(dump('tests')['testList'], param)
63
+ end
64
+ end
65
+ end
52
66
 
53
67
  def search_fullpage param, style
54
68
  unless param['id'].nil?
@@ -93,9 +107,60 @@ module InstaMonitis
93
107
  def delete_fullpage id
94
108
  push("deleteFullPageLoadMonitor&monitorId=#{id}")
95
109
  end
110
+
111
+ def report_http id, dayrange
112
+ # Grab URL for that HTTP Monitor
113
+ param = Hash.new
114
+ param['id'] = id
115
+ reporturl = search_http_quiet(param)['url']
116
+
117
+ # Get the dates in order
118
+ from = Date.today
119
+ to = ( from - dayrange )
120
+
121
+ # Place to put data
122
+ storage = Array.new
123
+
124
+ from.downto(to){ |date|
125
+ puts "Issuing API requests for #{date}.."
126
+ pull_http_results(id, date).each do |location|
127
+ location['data'].each do |data|
128
+ temp = Array.new
129
+ temp << reporturl
130
+ temp << location['locationName']
131
+ temp << data
132
+ storage << temp.flatten!
133
+ end
134
+ end
135
+ }
136
+ write_csv(( storage.sort_by { |data| data[2] } ), reporturl)
137
+ end
96
138
 
97
139
  private
98
140
 
141
+ def write_csv array, url
142
+ file = ENV['HOME'] + "/monitis-report-#{url}-" + Date.today.to_s + ".csv"
143
+ CSV.open(file, "wb") do |csv|
144
+ csv << [ "URL", "LOCATION", "DATE", "TIME", "HTTP" ]
145
+ array.each do |data|
146
+ csv << data
147
+ end
148
+ end
149
+ end
150
+
151
+ def construct_result_action id, date
152
+ return "testresult&testId=#{id}&year=#{date.year}&month=#{date.month}&day=#{date.day}"
153
+ end
154
+
155
+ def pull_http_results id, date
156
+ begin
157
+ return @monitis.get(construct_result_action(id, date))
158
+ rescue
159
+ puts "API failure? You're not supposed to be here. Exiting."
160
+ exit
161
+ end
162
+ end
163
+
99
164
  def dump action
100
165
  begin
101
166
  return @monitis.get(action.to_s)
@@ -28,7 +28,18 @@ module InstaMonitis
28
28
  return storage
29
29
  end
30
30
  end
31
-
31
+
32
+ def require_id options
33
+ storage = options.reject { |k, v| k == 'verbose' }
34
+ storage.reject! { |k, v| k == 'style' }
35
+ if storage[:id].nil?
36
+ puts "Generating a report requires a test id."
37
+ exit
38
+ else
39
+ return storage
40
+ end
41
+ end
42
+
32
43
  def check_file file
33
44
  if File.exist? file
34
45
  if file.include? '.csv'
@@ -125,7 +136,7 @@ module InstaMonitis
125
136
 
126
137
  class Del < Thor
127
138
  class_option :id, :aliases => '-i', :type => :numeric, :desc => 'Id of test'
128
- desc "http --id=[ID]", "Delete the http test with given Id"
139
+ desc "http --id=[N]", "Delete the http test with given Id"
129
140
  long_desc <<-LONGDESC
130
141
  There is no undo, given an Id go nuclear and nuke it from orbit.
131
142
  LONGDESC
@@ -133,7 +144,7 @@ module InstaMonitis
133
144
  Backend.new.delete_http(options[:id])
134
145
  end
135
146
 
136
- desc "page --id=[ID]", "Delete the full page load test with given Id"
147
+ desc "page --id=[N]", "Delete the full page load test with given Id"
137
148
  long_desc <<-LONGDESC
138
149
  There is no undo, given an Id go nuclear and nuke it from orbit.
139
150
  LONGDESC
@@ -184,6 +195,26 @@ module InstaMonitis
184
195
  end
185
196
  end
186
197
 
198
+ class Report < Thor
199
+ include RunnerHelper
200
+ class_option :id, :aliases => '-i', :type => :numeric, :desc => 'Id of test'
201
+ class_option :days, :aliases => '-d', :type => :numeric, :desc => 'How many days', :default => 150
202
+ desc "http --[ID]=[N] --[DAYS]=[N]", "Generate report for given http test"
203
+ long_desc <<-LONGDESC
204
+ Using the API, generate a .csv report of a HTTP Monitor going back [x] days.
205
+
206
+ For a given id ( -i, --id ), use the api to pull every day going back to [x] days.
207
+
208
+ If the amount of days ( -d, --days ), isn't set, it will default to 150 days.
209
+
210
+ Combine the results sanely, and dump it into a .csv file.
211
+ LONGDESC
212
+ def http()
213
+ this = Backend.new
214
+ this.report_http(require_id(options)[:id], options[:days])
215
+ end
216
+ end
217
+
187
218
  class Runner < Thor
188
219
  class_option :verbose, :aliases => '-v', :type => :boolean
189
220
 
@@ -199,6 +230,9 @@ module InstaMonitis
199
230
  desc "search [COMMAND] [ARGS]", "Perform search operations"
200
231
  subcommand "search", Search
201
232
 
233
+ desc "report [COMMAND] [ARGS]", "Perform report operations"
234
+ subcommand "report", Report
235
+
202
236
  no_commands do
203
237
  def log(str)
204
238
  puts str if options[:verbose]
@@ -1,3 +1,3 @@
1
1
  module InstaMonitis
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: insta-monitis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Pramann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-09 00:00:00.000000000 Z
11
+ date: 2015-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor