ix-cli 0.0.16 → 0.0.18

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
  SHA256:
3
- metadata.gz: 1457129da9fa04dd6d4241cf824afc2998a0302cdf9bd4b915088f61b48f53ac
4
- data.tar.gz: 1837dc100f225e4fd9d919465003c3874d629ec6a5e5f2b125625ea82a588947
3
+ metadata.gz: 0c092a50cdc78203f0d6b63eaf7ab134ef75c6fcd2359433f30ccc75a1927fa4
4
+ data.tar.gz: b56649886c4163ce425c95fdf178db6255983b0bd093af8dc8f7b92e5a1734a8
5
5
  SHA512:
6
- metadata.gz: 97c0c9b0879c2c6b557e09907db966a0a2fbdcbfade5477ac60ddc77fd9367b41bb5ddbd6a60b66525cf45dbe305872812cb0789f962395cd6347a671db1463b
7
- data.tar.gz: dced22aa4a1e694ceaf0aa4113e6d7b7c6e5d6e4e175cd18e4a2ade63c1c141780a045ff40f138df6584f39f7fa2f0d9ab2ad9b04fd21db180c2c1f1c15e3c6b
6
+ metadata.gz: ffff3b4215e024457a8271bd2c670a50df67309b5753fa91d6940c917b7e2e91c0c7803b92d568dcb79a9cabee6699a6a1f54901ab6a9a3ead4d1ed7fe1f1375
7
+ data.tar.gz: 2f291e87dd401b6b11c3601ff11e05d403cb10bc2452fb773cd063c3789a3ceb8c90ce2af04585f25de376d8e52759f126104567efd71ca5725cd4fe93b9ea5d
data/bin/ix-bcat CHANGED
@@ -187,6 +187,9 @@ OptionParser.new do |opts|
187
187
  options[:pre] = value
188
188
  end
189
189
 
190
+ opts.on('-d', '--dark', 'Dark mode.') do |value|
191
+ options[:dark] = value
192
+ end
190
193
 
191
194
  end.parse!
192
195
 
@@ -205,12 +208,19 @@ STDIN.each_line do |line|
205
208
  end
206
209
 
207
210
  if options[:pre]
208
- puts '<pre>'
211
+ if options[:dark]
212
+ puts "<body style='background-color:#222;'>"
213
+ puts "<pre style='color:gray;'>"
214
+ else
215
+ puts "<body>"
216
+ puts "<pre>"
217
+ end
209
218
  end
210
219
 
211
220
  puts Bcat::ANSI.new(data).to_html
212
221
 
213
222
  if options[:pre]
214
223
  puts '</pre>'
224
+ puts '</body>'
215
225
  end
216
226
 
data/bin/ix-center ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+
5
+ options = {}
6
+ options[:width] = 40
7
+
8
+ OptionParser.new do |opts|
9
+
10
+ opts.banner = "Usage: #{$0} [OPTIONS]"
11
+
12
+ opts.on('-w', '--width [NUMBER]', 'Width.') do |value|
13
+ options[:width] = value.to_i
14
+ end
15
+
16
+ end.parse!
17
+
18
+ required_options = [:width]
19
+ required_options.each do |option|
20
+ unless options[option]
21
+ $stderr.puts "Can not run #{option.to_s} was not given."
22
+ exit 1
23
+ end
24
+ end
25
+
26
+ STDIN.each_line do |line|
27
+ puts line.chomp.center(options[:width])
28
+ end
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'json'
4
+
5
+ headers = []
6
+
7
+ STDIN.each_line do |line|
8
+
9
+ line.chomp!
10
+
11
+ if line =~ /^#Version:/
12
+ next
13
+ end
14
+
15
+ if line =~ /^#Fields:/
16
+ fields = line.split(/^#Fields: /)[1..-1][0]
17
+ headers = fields.split(/\s+/)
18
+ next
19
+ end
20
+
21
+ values = line.split(/\t/)
22
+
23
+ data = {}
24
+
25
+ headers.each_with_index do |header, index|
26
+ data[header] = values[index]
27
+ end
28
+
29
+ puts data.to_json
30
+
31
+ end
data/bin/ix-cycle ADDED
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+
5
+ options = {}
6
+
7
+ OptionParser.new do |opts|
8
+
9
+ opts.banner = "Usage: #{$0} [OPTIONS]"
10
+
11
+ opts.on('-r', '--range [RANGE]', 'Range, for example 1..10') do |value|
12
+ options[:range] = value
13
+ end
14
+
15
+ opts.on('-l', '--limit [NUMBER]', 'Limit, the max number of times to cycle through the range') do |value|
16
+ options[:limit] = value.to_i
17
+ end
18
+
19
+ end.parse!
20
+
21
+ required_options = [:range, :limit]
22
+ required_options.each do |option|
23
+ unless options[option]
24
+ $stderr.puts "Can not run #{option.to_s} was not given."
25
+ exit 1
26
+ end
27
+ end
28
+
29
+ class Cycle
30
+ def initialize(range)
31
+ @range = range
32
+ @index = -1
33
+ end
34
+
35
+ def next
36
+ @index += 1
37
+ @index = 0 if @index >= @range.size
38
+ @range[@index]
39
+ end
40
+ end
41
+
42
+ range = eval(options[:range]).to_a
43
+ cycle = Cycle.new(range)
44
+
45
+ counter = 0
46
+
47
+ STDIN.each_line do |line|
48
+ line.chomp!
49
+ # puts "#{line} #{cycle.next}"
50
+ puts cycle.next
51
+ counter += 1
52
+ break if options[:limit] && counter >= options[:limit].to_i
53
+ end
54
+
data/bin/ix-df-to-json ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # /dev/xvdi 2.9T 1.2T 1.7T 42% /ebs/stage-new
4
+
5
+ require 'isna'
6
+ require 'json'
7
+
8
+ reports = []
9
+
10
+ STDIN.each_line do |line|
11
+ next if line =~ /Used/
12
+ chunks = line.chomp.split(/\s+/)
13
+
14
+ hash = { }
15
+ hash["device"] = chunks[0]
16
+ hash["total_size"] = chunks[1]
17
+ hash["space_used"] = chunks[2]
18
+ hash["space_available"] = chunks[3]
19
+ hash["percentage_used"] = chunks[4]
20
+ hash["mount_point"] = chunks[5]
21
+ hash["mount_point"] = chunks[5]
22
+ hash["timestamp"] = Time.now.to_i
23
+
24
+ reports << hash
25
+ end
26
+
27
+ reports.sort do |a, b|
28
+ pna = a["percentage_used"].scan(/\d+/)[0]
29
+ pnb = b["percentage_used"].scan(/\d+/)[0]
30
+ pna.to_i <=> pnb.to_i
31
+ end.reverse.each do |report|
32
+ puts report.to_json
33
+ end
data/bin/ix-df2 ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # /dev/xvdi 2.9T 1.2T 1.7T 42% /ebs/stage-new
4
+
5
+ require 'isna'
6
+
7
+ reports = []
8
+
9
+ STDIN.each_line do |line|
10
+ next if line =~ /Used/
11
+ chunks = line.chomp.split(/\s+/)
12
+
13
+ hash = { }
14
+ hash["Device"] = chunks[0]
15
+ hash["Total Size"] = chunks[1]
16
+ hash["Space Used"] = chunks[2]
17
+ hash["Space Available"] = chunks[3]
18
+ hash["Percentage Used"] = chunks[4]
19
+ hash["Mount Point"] = chunks[5]
20
+
21
+ reports << hash
22
+ end
23
+
24
+ reports.sort do |a, b|
25
+ pna = a["Percentage Used"].scan(/\d+/)[0]
26
+ pnb = b["Percentage Used"].scan(/\d+/)[0]
27
+ pna.to_i <=> pnb.to_i
28
+ end.reverse.each do |report|
29
+ puts ''
30
+ report.each do |key, value|
31
+ puts "#{key.ljust(20).to_ansi.green.to_s}: #{value}"
32
+ end
33
+ pn = report["Percentage Used"].scan(/\d+/)[0]
34
+ puts `echo #{pn} 100 | ix gauge`
35
+ end
36
+
37
+ puts ''
38
+
39
+ # puts "Report generated on #{Time.now}"
40
+
data/bin/ix-domain-dns ADDED
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'resolv'
5
+ require 'json'
6
+
7
+ STDIN.each_line do |line|
8
+
9
+ domain = line.chomp
10
+
11
+ begin
12
+
13
+ Resolv::DNS.open do |dns|
14
+ dns.each_resource(domain, Resolv::DNS::Resource::IN::A) do |r|
15
+ puts ({ :type => 'A', :value => r.address.to_s, :ttl => r.ttl, :domain => domain }).to_json
16
+ end
17
+
18
+ dns.each_resource(domain, Resolv::DNS::Resource::IN::AAAA) do |r|
19
+ puts ({ :type => 'AAAA', :value => r.address.to_s, :ttl => r.ttl, :domain => domain }).to_json
20
+ end
21
+
22
+ dns.each_resource(domain, Resolv::DNS::Resource::IN::SOA) do |r|
23
+ puts ({ :type => 'SOA', :value => r.mname.to_s, :ttl => r.ttl, :domain => domain }).to_json
24
+ end
25
+
26
+ dns.each_resource(domain, Resolv::DNS::Resource::IN::NS) do |r|
27
+ puts ({ :type => 'NS', :value => r.name.to_s, :ttl => r.ttl, :domain => domain }).to_json
28
+ end
29
+
30
+ dns.each_resource(domain, Resolv::DNS::Resource::IN::MX) do |r|
31
+ puts ({ :type => 'MX', :value => r.exchange.to_s, :ttl => r.ttl, :domain => domain }).to_json
32
+ end
33
+
34
+ dns.each_resource(domain, Resolv::DNS::Resource::IN::TXT) do |r|
35
+ puts ({ :type => 'TXT', :value => r.data.to_s, :ttl => r.ttl, :domain => domain }).to_json
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+
@@ -0,0 +1,217 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'json'
5
+ require 'time'
6
+
7
+ def debug(chunks)
8
+ chunks.each_with_index do |value, index|
9
+ puts [index, value].inspect
10
+ end
11
+ end
12
+
13
+ def parse_section_0(object, section)
14
+ chunks = section.split(' ')
15
+ object[:type] = chunks[0]
16
+ time = Time.parse(chunks[1])
17
+ object[:time] = time
18
+ object[:timestamp] = time.to_f
19
+ object[:elb] = chunks[2]
20
+ client, port = chunks[3].split(':')
21
+ object[:client] = client
22
+ object[:client_port] = port.to_i
23
+ client, port = chunks[4].split(':')
24
+ object[:target] = client
25
+ object[:target_port] = port.to_i
26
+ object[:request_processing_time] = chunks[5].to_f
27
+ object[:target_processing_time] = chunks[6].to_f
28
+ object[:response_processing_time] = chunks[7].to_f
29
+ object[:elb_status_code] = chunks[8].to_i
30
+ object[:target_status_code] = chunks[9].to_i
31
+ object[:received_bytes] = chunks[10].to_i
32
+ object[:sent_bytes] = chunks[11].to_i
33
+ nil
34
+ end
35
+
36
+ def parse_section_1(object, section)
37
+ chunks = section.split(' ')
38
+ object[:http_method] = chunks[0]
39
+ object[:request_url] = chunks[1]
40
+ object[:http_protocol] = chunks[2]
41
+ nil
42
+ end
43
+
44
+ def parse_section_2(object, section)
45
+ nil
46
+ end
47
+
48
+ def parse_section_3(object, section)
49
+ object[:user_agent] = section
50
+ nil
51
+ end
52
+
53
+ def parse_section_4(object, section)
54
+ chunks = section.split(' ')
55
+ object[:ssl_cipher] = chunks[0]
56
+ object[:ssl_protocol] = chunks[1]
57
+ object[:target_group_arn] = chunks[2]
58
+ nil
59
+ end
60
+
61
+ def parse_section_5(object, section)
62
+ object[:trace_id] = section
63
+ nil
64
+ end
65
+
66
+ def parse_section_6(object, section)
67
+ nil
68
+ end
69
+
70
+ def parse_section_7(object, section)
71
+ object[:domain_name] = section
72
+ nil
73
+ end
74
+
75
+ def parse_section_8(object, section)
76
+ nil
77
+ end
78
+
79
+ def parse_section_9(object, section)
80
+ object[:chosen_cert_arn] = section
81
+ nil
82
+ end
83
+
84
+ def parse_section_10(object, section)
85
+ chunks = section.split(' ')
86
+ object[:matched_rule_priority] = chunks[0]
87
+ time = Time.parse(chunks[1])
88
+ object[:request_creation_time] = time
89
+ object[:request_creation_timestamp] = time.to_f
90
+ nil
91
+ end
92
+
93
+ def parse_section_11(object, section)
94
+ object[:actions_executed] = section
95
+ nil
96
+ end
97
+
98
+ def parse_section_12(object, section)
99
+ nil
100
+ end
101
+
102
+ def parse_section_13(object, section)
103
+ nil
104
+ end
105
+
106
+ def parse_section_14(object, section)
107
+ nil
108
+ end
109
+
110
+ def parse_section_15(object, section)
111
+ nil
112
+ end
113
+
114
+ def parse_section_16(object, section)
115
+ nil
116
+ end
117
+
118
+ def parse_section_17(object, section)
119
+ object[:target_port_list] = section
120
+ nil
121
+ end
122
+
123
+ def parse_section_17(object, section)
124
+ object[:target_port_list] = section
125
+ nil
126
+ end
127
+
128
+ def parse_section_18(object, section)
129
+ nil
130
+ end
131
+
132
+ def parse_section_19(object, section)
133
+ object[:target_status_code_list] = section
134
+ nil
135
+ end
136
+
137
+ def parse_section_20(object, section)
138
+ nil
139
+ end
140
+
141
+ def parse_section_21(object, section)
142
+ nil
143
+ end
144
+
145
+ def parse_section_22(object, section)
146
+ nil
147
+ end
148
+
149
+ def parse_section_23(object, section)
150
+ nil
151
+ end
152
+
153
+ require 'optparse'
154
+
155
+ options = {}
156
+
157
+ OptionParser.new do |opts|
158
+
159
+ opts.banner = "Usage: #{$0} [OPTIONS]"
160
+
161
+ opts.on('-d', '--debug', 'Debug.') do |value|
162
+ options[:debug] = value
163
+ end
164
+
165
+ end.parse!
166
+
167
+ required_options = []
168
+ required_options.each do |option|
169
+ unless options[option]
170
+ $stderr.puts "Can not run #{option.to_s} was not given."
171
+ exit 1
172
+ end
173
+ end
174
+
175
+ # reference:
176
+ # https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-access-logs.html#access-log-entry-format
177
+
178
+ c = 0
179
+
180
+ # client:
181
+ STDIN.each_line do |line|
182
+ begin
183
+ line.chomp!
184
+ object = {}
185
+ chunks = line.split('"')
186
+ debug(chunks) if options[:debug]
187
+ parse_section_0(object, chunks[0])
188
+ parse_section_1(object, chunks[1])
189
+ parse_section_2(object, chunks[2])
190
+ parse_section_3(object, chunks[3])
191
+ parse_section_4(object, chunks[4])
192
+ parse_section_5(object, chunks[5])
193
+ parse_section_6(object, chunks[6])
194
+ parse_section_7(object, chunks[7])
195
+ parse_section_8(object, chunks[8])
196
+ parse_section_9(object, chunks[9])
197
+ parse_section_10(object, chunks[10])
198
+ parse_section_11(object, chunks[11])
199
+ parse_section_12(object, chunks[12])
200
+ parse_section_13(object, chunks[13])
201
+ parse_section_14(object, chunks[14])
202
+ parse_section_15(object, chunks[15])
203
+ parse_section_16(object, chunks[16])
204
+ parse_section_17(object, chunks[17])
205
+ parse_section_18(object, chunks[18])
206
+ parse_section_19(object, chunks[19])
207
+ parse_section_20(object, chunks[20])
208
+ parse_section_21(object, chunks[21])
209
+ parse_section_22(object, chunks[22])
210
+ parse_section_23(object, chunks[23])
211
+ puts object.to_json
212
+ rescue => error
213
+ c += 1
214
+ end
215
+ end
216
+
217
+ $stderr.puts "Error count: #{c}" if c > 0
data/bin/ix-hls CHANGED
@@ -1,17 +1,25 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'rubygems'
3
+ #
4
+ # options
5
+ #
6
+ # line ix-highlight-line highlight a specific line
7
+ # vertical ix-highlight-vertical highlight a particular column
8
+ # highlight ix-highlight-match highlight whatever matches a regex
9
+ #
10
+
4
11
  require 'isna'
5
12
 
6
13
  abort 'No pattern given' if ARGV[0].nil?
7
14
 
8
15
  trap('SIGINT') { }
9
16
 
17
+ $stdout.sync = true
18
+
10
19
  STDIN.each_line do |line|
11
- ARGV.each do |setting|
12
- matcher, color = setting.split(':')
13
- line.gsub!(/(#{matcher})/i) { |x| "#{$1}".to_ansi.send(:"#{color}").to_s }
20
+ ARGV.each do |arg|
21
+ chunks = arg.split(':')
22
+ puts line.gsub(/(#{chunks[0]})/i) { |x| $1.to_ansi.send(chunks[1].to_sym).to_s }
14
23
  end
15
- puts line
16
24
  end
17
25
 
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'json'
4
+
5
+ require 'optparse'
6
+
7
+ options = {}
8
+
9
+ OptionParser.new do |opts|
10
+
11
+ opts.banner = "Usage: #{$0} [OPTIONS]"
12
+
13
+ opts.on('-f', '--field [NAME]', 'Field.') do |value|
14
+ options[:field] = value
15
+ end
16
+
17
+ opts.on('-m', '--match [REGEX]', 'Match.') do |value|
18
+ options[:match] = value
19
+ end
20
+
21
+ end.parse!
22
+
23
+ required_options = [:field, :match]
24
+ required_options.each do |option|
25
+ unless options[option]
26
+ $stderr.puts "Can not run #{option.to_s} was not given."
27
+ exit 1
28
+ end
29
+ end
30
+
31
+ STDIN.each_line do |line|
32
+ begin
33
+ json = JSON.parse(line)
34
+ if json[options[:field]].to_s =~ /#{options[:match]}/
35
+ puts line
36
+ end
37
+ rescue JSON::ParserError => e
38
+ $stderr.puts "Error parsing line: #{line}"
39
+ end
40
+ end
41
+
data/bin/ix-json-join ADDED
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'json'
4
+
5
+ require 'optparse'
6
+
7
+ options = {}
8
+
9
+ OptionParser.new do |opts|
10
+
11
+ opts.banner = "Usage: #{$0} [OPTIONS]"
12
+
13
+ opts.on('-l', '--left-file [FILE]', 'Left file.') do |value|
14
+ options[:left_file] = value
15
+ end
16
+
17
+ opts.on('-r', '--right-file [FILE]', 'Right file.') do |value|
18
+ options[:right_file] = value
19
+ end
20
+
21
+ opts.on('-e', '--left-key [JSON_FIELD_NAME]', 'Left key.') do |value|
22
+ options[:left_key] = value
23
+ end
24
+
25
+ opts.on('-i', '--right-key [JSON_FIELD_NAME]', 'Right key.') do |value|
26
+ options[:right_key] = value
27
+ end
28
+
29
+ opts.on('-f', '--left-prefix [STRING]', 'Left prefix to use for every field on LEFT json.') do |value|
30
+ options[:left_prefix] = value
31
+ end
32
+
33
+ opts.on('-g', '--right-prefix [STRING]', 'Right prefix to use for every field on RIGHT json.') do |value|
34
+ options[:right_prefix] = value
35
+ end
36
+
37
+ end.parse!
38
+
39
+ required_options = [:left_file, :right_file, :left_key, :right_key, :left_prefix, :right_prefix]
40
+ required_options.each do |option|
41
+ unless options[option]
42
+ $stderr.puts "Can not run #{option.to_s} was not given."
43
+ exit 1
44
+ end
45
+ end
46
+
47
+ left = []
48
+ right = []
49
+ join = []
50
+
51
+ File.read(options[:left_file]).each_line do |line|
52
+ left << JSON.parse(line)
53
+ end
54
+
55
+ File.read(options[:right_file]).each_line do |line|
56
+ right << JSON.parse(line)
57
+ end
58
+
59
+ left.each do |left_item|
60
+ right.each do |right_item|
61
+ if left_item[options[:left_key]] == right_item[options[:right_key]]
62
+ join_object = {}
63
+ left_item.each do |key, value|
64
+ join_object[options[:left_prefix] + '_' + key] = value
65
+ end
66
+ right_item.each do |key, value|
67
+ join_object[options[:right_prefix] + '_' + key] = value
68
+ end
69
+ join << join_object
70
+ end
71
+ end
72
+ end
73
+
74
+ join.each do |join_item|
75
+ puts join_item.to_json
76
+ end
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ puts 'write this in honor of omar'
data/bin/ix-json-swap ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'json'
4
+
5
+ STDIN.each_line do |line|
6
+ object = JSON.parse(line)
7
+ puts object.invert.to_json
8
+ end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'json'
4
+ require 'yaml'
5
+
6
+ puts JSON.parse(STDIN.read).to_yaml
data/bin/ix-ljust ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ STDIN.each_line do |line|
4
+ puts line.chomp.ljust(ARGV[0].to_i)
5
+ end