sabisu 0.1.1 → 0.1.2

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: b03b7b9b016b02db02642e91e5dd8a920be20e29
4
- data.tar.gz: 26dcde4dbeece04c693a1a0cb6a31cad528bd291
3
+ metadata.gz: fa060f7f6d3fa47aceec7fe11848ccd49a24bcf1
4
+ data.tar.gz: a572075e53fe1902580e0a97b2b123384a8e27fa
5
5
  SHA512:
6
- metadata.gz: fb6bd7f38caccf9cb429393dcb5b15de530f67a17f3849c58c03b82f35d24949342930676788dd55b0075a3cc65b8fc4bee28ff019417ef2ddf0a6fc1056960e
7
- data.tar.gz: 3e75838b3e0a10e74e26ab8c223b8cb8eb62c3b15c2dedf6e5897d36b04d71ce12dfb7a1d561360d7775e84df3fad42187afbb87cef5d581e0cd4694fb4f90d0
6
+ metadata.gz: 34dfc58ca272d41d17a3881ce0f0e9d0d48c9cbf15c5d9fc13146e0c82c657d283764fd0ed299452e540c0f9c9b4b3612b183cacedeb9c0ce77b75d8aafd9838
7
+ data.tar.gz: 3a5c403d17ab713587595d6514d072080cdf94d161672aeb548d362c602a94654520fe9f29ad2c653fc2aae0a5efec23dce3807efdaad0b80dc0b20bd85e27d2
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Build Status](https://magnum.travis-ci.com/cloudant/sabisu.png?token=r6PdrwNFR1nUzFeEEiQ6&branch=master)](https://magnum.travis-ci.com/cloudant/sabisu)
1
+ [![Build Status](https://travis-ci.org/cloudant/sabisu.svg?branch=master)](https://travis-ci.org/cloudant/sabisu)
2
2
  sabisu
3
3
  ======
4
4
 
@@ -6,7 +6,7 @@ module Sabisu
6
6
  # return all docs
7
7
  def self.all(options = {})
8
8
  options = { skip: 0, limit: nil, sort: [] }.merge(options)
9
- options.delete_if { |k, v| v.nil? || v == [] }
9
+ options.delete_if { |_k, v| v.nil? || v == [] }
10
10
 
11
11
  CURRENT_DB.all_docs(options.merge(include_docs: true, start_key: '"a"'))
12
12
  end
@@ -33,7 +33,7 @@ module Sabisu
33
33
  ranges: ranges.to_json,
34
34
  counts: counts
35
35
  }.merge(options)
36
- options.delete_if { |k, v| v.nil? || v == [] }
36
+ options.delete_if { |_k, v| v.nil? || v == [] }
37
37
  # because couchrest doesn't handle arrays correctly
38
38
  options[:counts] = options[:counts].to_s unless options[:counts].nil?
39
39
  options[:sort] = options[:sort].to_s unless options[:sort].nil?
@@ -0,0 +1,19 @@
1
+ /*
2
+ CryptoJS v3.1.2
3
+ code.google.com/p/crypto-js
4
+ (c) 2009-2013 by Jeff Mott. All rights reserved.
5
+ code.google.com/p/crypto-js/wiki/License
6
+ */
7
+ var CryptoJS=CryptoJS||function(s,p){var m={},l=m.lib={},n=function(){},r=l.Base={extend:function(b){n.prototype=this;var h=new n;b&&h.mixIn(b);h.hasOwnProperty("init")||(h.init=function(){h.$super.init.apply(this,arguments)});h.init.prototype=h;h.$super=this;return h},create:function(){var b=this.extend();b.init.apply(b,arguments);return b},init:function(){},mixIn:function(b){for(var h in b)b.hasOwnProperty(h)&&(this[h]=b[h]);b.hasOwnProperty("toString")&&(this.toString=b.toString)},clone:function(){return this.init.prototype.extend(this)}},
8
+ q=l.WordArray=r.extend({init:function(b,h){b=this.words=b||[];this.sigBytes=h!=p?h:4*b.length},toString:function(b){return(b||t).stringify(this)},concat:function(b){var h=this.words,a=b.words,j=this.sigBytes;b=b.sigBytes;this.clamp();if(j%4)for(var g=0;g<b;g++)h[j+g>>>2]|=(a[g>>>2]>>>24-8*(g%4)&255)<<24-8*((j+g)%4);else if(65535<a.length)for(g=0;g<b;g+=4)h[j+g>>>2]=a[g>>>2];else h.push.apply(h,a);this.sigBytes+=b;return this},clamp:function(){var b=this.words,h=this.sigBytes;b[h>>>2]&=4294967295<<
9
+ 32-8*(h%4);b.length=s.ceil(h/4)},clone:function(){var b=r.clone.call(this);b.words=this.words.slice(0);return b},random:function(b){for(var h=[],a=0;a<b;a+=4)h.push(4294967296*s.random()|0);return new q.init(h,b)}}),v=m.enc={},t=v.Hex={stringify:function(b){var a=b.words;b=b.sigBytes;for(var g=[],j=0;j<b;j++){var k=a[j>>>2]>>>24-8*(j%4)&255;g.push((k>>>4).toString(16));g.push((k&15).toString(16))}return g.join("")},parse:function(b){for(var a=b.length,g=[],j=0;j<a;j+=2)g[j>>>3]|=parseInt(b.substr(j,
10
+ 2),16)<<24-4*(j%8);return new q.init(g,a/2)}},a=v.Latin1={stringify:function(b){var a=b.words;b=b.sigBytes;for(var g=[],j=0;j<b;j++)g.push(String.fromCharCode(a[j>>>2]>>>24-8*(j%4)&255));return g.join("")},parse:function(b){for(var a=b.length,g=[],j=0;j<a;j++)g[j>>>2]|=(b.charCodeAt(j)&255)<<24-8*(j%4);return new q.init(g,a)}},u=v.Utf8={stringify:function(b){try{return decodeURIComponent(escape(a.stringify(b)))}catch(g){throw Error("Malformed UTF-8 data");}},parse:function(b){return a.parse(unescape(encodeURIComponent(b)))}},
11
+ g=l.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new q.init;this._nDataBytes=0},_append:function(b){"string"==typeof b&&(b=u.parse(b));this._data.concat(b);this._nDataBytes+=b.sigBytes},_process:function(b){var a=this._data,g=a.words,j=a.sigBytes,k=this.blockSize,m=j/(4*k),m=b?s.ceil(m):s.max((m|0)-this._minBufferSize,0);b=m*k;j=s.min(4*b,j);if(b){for(var l=0;l<b;l+=k)this._doProcessBlock(g,l);l=g.splice(0,b);a.sigBytes-=j}return new q.init(l,j)},clone:function(){var b=r.clone.call(this);
12
+ b._data=this._data.clone();return b},_minBufferSize:0});l.Hasher=g.extend({cfg:r.extend(),init:function(b){this.cfg=this.cfg.extend(b);this.reset()},reset:function(){g.reset.call(this);this._doReset()},update:function(b){this._append(b);this._process();return this},finalize:function(b){b&&this._append(b);return this._doFinalize()},blockSize:16,_createHelper:function(b){return function(a,g){return(new b.init(g)).finalize(a)}},_createHmacHelper:function(b){return function(a,g){return(new k.HMAC.init(b,
13
+ g)).finalize(a)}}});var k=m.algo={};return m}(Math);
14
+ (function(s){function p(a,k,b,h,l,j,m){a=a+(k&b|~k&h)+l+m;return(a<<j|a>>>32-j)+k}function m(a,k,b,h,l,j,m){a=a+(k&h|b&~h)+l+m;return(a<<j|a>>>32-j)+k}function l(a,k,b,h,l,j,m){a=a+(k^b^h)+l+m;return(a<<j|a>>>32-j)+k}function n(a,k,b,h,l,j,m){a=a+(b^(k|~h))+l+m;return(a<<j|a>>>32-j)+k}for(var r=CryptoJS,q=r.lib,v=q.WordArray,t=q.Hasher,q=r.algo,a=[],u=0;64>u;u++)a[u]=4294967296*s.abs(s.sin(u+1))|0;q=q.MD5=t.extend({_doReset:function(){this._hash=new v.init([1732584193,4023233417,2562383102,271733878])},
15
+ _doProcessBlock:function(g,k){for(var b=0;16>b;b++){var h=k+b,w=g[h];g[h]=(w<<8|w>>>24)&16711935|(w<<24|w>>>8)&4278255360}var b=this._hash.words,h=g[k+0],w=g[k+1],j=g[k+2],q=g[k+3],r=g[k+4],s=g[k+5],t=g[k+6],u=g[k+7],v=g[k+8],x=g[k+9],y=g[k+10],z=g[k+11],A=g[k+12],B=g[k+13],C=g[k+14],D=g[k+15],c=b[0],d=b[1],e=b[2],f=b[3],c=p(c,d,e,f,h,7,a[0]),f=p(f,c,d,e,w,12,a[1]),e=p(e,f,c,d,j,17,a[2]),d=p(d,e,f,c,q,22,a[3]),c=p(c,d,e,f,r,7,a[4]),f=p(f,c,d,e,s,12,a[5]),e=p(e,f,c,d,t,17,a[6]),d=p(d,e,f,c,u,22,a[7]),
16
+ c=p(c,d,e,f,v,7,a[8]),f=p(f,c,d,e,x,12,a[9]),e=p(e,f,c,d,y,17,a[10]),d=p(d,e,f,c,z,22,a[11]),c=p(c,d,e,f,A,7,a[12]),f=p(f,c,d,e,B,12,a[13]),e=p(e,f,c,d,C,17,a[14]),d=p(d,e,f,c,D,22,a[15]),c=m(c,d,e,f,w,5,a[16]),f=m(f,c,d,e,t,9,a[17]),e=m(e,f,c,d,z,14,a[18]),d=m(d,e,f,c,h,20,a[19]),c=m(c,d,e,f,s,5,a[20]),f=m(f,c,d,e,y,9,a[21]),e=m(e,f,c,d,D,14,a[22]),d=m(d,e,f,c,r,20,a[23]),c=m(c,d,e,f,x,5,a[24]),f=m(f,c,d,e,C,9,a[25]),e=m(e,f,c,d,q,14,a[26]),d=m(d,e,f,c,v,20,a[27]),c=m(c,d,e,f,B,5,a[28]),f=m(f,c,
17
+ d,e,j,9,a[29]),e=m(e,f,c,d,u,14,a[30]),d=m(d,e,f,c,A,20,a[31]),c=l(c,d,e,f,s,4,a[32]),f=l(f,c,d,e,v,11,a[33]),e=l(e,f,c,d,z,16,a[34]),d=l(d,e,f,c,C,23,a[35]),c=l(c,d,e,f,w,4,a[36]),f=l(f,c,d,e,r,11,a[37]),e=l(e,f,c,d,u,16,a[38]),d=l(d,e,f,c,y,23,a[39]),c=l(c,d,e,f,B,4,a[40]),f=l(f,c,d,e,h,11,a[41]),e=l(e,f,c,d,q,16,a[42]),d=l(d,e,f,c,t,23,a[43]),c=l(c,d,e,f,x,4,a[44]),f=l(f,c,d,e,A,11,a[45]),e=l(e,f,c,d,D,16,a[46]),d=l(d,e,f,c,j,23,a[47]),c=n(c,d,e,f,h,6,a[48]),f=n(f,c,d,e,u,10,a[49]),e=n(e,f,c,d,
18
+ C,15,a[50]),d=n(d,e,f,c,s,21,a[51]),c=n(c,d,e,f,A,6,a[52]),f=n(f,c,d,e,q,10,a[53]),e=n(e,f,c,d,y,15,a[54]),d=n(d,e,f,c,w,21,a[55]),c=n(c,d,e,f,v,6,a[56]),f=n(f,c,d,e,D,10,a[57]),e=n(e,f,c,d,t,15,a[58]),d=n(d,e,f,c,B,21,a[59]),c=n(c,d,e,f,r,6,a[60]),f=n(f,c,d,e,z,10,a[61]),e=n(e,f,c,d,j,15,a[62]),d=n(d,e,f,c,x,21,a[63]);b[0]=b[0]+c|0;b[1]=b[1]+d|0;b[2]=b[2]+e|0;b[3]=b[3]+f|0},_doFinalize:function(){var a=this._data,k=a.words,b=8*this._nDataBytes,h=8*a.sigBytes;k[h>>>5]|=128<<24-h%32;var l=s.floor(b/
19
+ 4294967296);k[(h+64>>>9<<4)+15]=(l<<8|l>>>24)&16711935|(l<<24|l>>>8)&4278255360;k[(h+64>>>9<<4)+14]=(b<<8|b>>>24)&16711935|(b<<24|b>>>8)&4278255360;a.sigBytes=4*(k.length+1);this._process();a=this._hash;k=a.words;for(b=0;4>b;b++)h=k[b],k[b]=(h<<8|h>>>24)&16711935|(h<<24|h>>>8)&4278255360;return a},clone:function(){var a=t.clone.call(this);a._hash=this._hash.clone();return a}});r.MD5=t._createHelper(q);r.HmacMD5=t._createHmacHelper(q)})(Math);
@@ -7,6 +7,7 @@ require 'sinatra/base'
7
7
  require 'sinatra/multi_route'
8
8
  require 'couchrest'
9
9
  require 'restclient'
10
+ require 'haml'
10
11
  require 'cgi'
11
12
  require 'json'
12
13
  require 'pp'
@@ -1,6 +1,6 @@
1
1
  %link{:rel => 'stylesheet', :href => '/css/events.css'}
2
2
  %script{:src => '/js/typeahead.js'}
3
- %script{:src => 'https://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js'}
3
+ %script{:src => '/js/md5.js'}
4
4
 
5
5
  #eventsController.row{'ng-controller' => 'eventsController'}
6
6
  -# last update time in corner
@@ -1,4 +1,4 @@
1
1
  # instantiate constants
2
2
  module Sabisu
3
- VERSION = '0.1.1' unless defined?(Sabisu::VERSION)
3
+ VERSION = '0.1.2' unless defined?(Sabisu::VERSION)
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sabisu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Barraford
@@ -9,216 +9,216 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-11 00:00:00.000000000 Z
12
+ date: 2016-06-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ~>
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
20
  version: 1.4.4
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ~>
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: 1.4.4
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: thin
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: sinatra-contrib
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - '>='
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - '>='
53
+ - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: haml
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - '>='
60
+ - - ">="
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - '>='
67
+ - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: couchrest
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - '>='
74
+ - - ">="
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - '>='
81
+ - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: restclient
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - '>='
88
+ - - ">="
89
89
  - !ruby/object:Gem::Version
90
90
  version: '0'
91
91
  type: :runtime
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - '>='
95
+ - - ">="
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: rack-ssl-enforcer
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - '>='
102
+ - - ">="
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  type: :runtime
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - '>='
109
+ - - ">="
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
112
  - !ruby/object:Gem::Dependency
113
113
  name: json
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - '>='
116
+ - - ">="
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  type: :runtime
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
- - - '>='
123
+ - - ">="
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: rubocop
128
128
  requirement: !ruby/object:Gem::Requirement
129
129
  requirements:
130
- - - '>='
130
+ - - ">="
131
131
  - !ruby/object:Gem::Version
132
132
  version: 0.19.1
133
133
  type: :development
134
134
  prerelease: false
135
135
  version_requirements: !ruby/object:Gem::Requirement
136
136
  requirements:
137
- - - '>='
137
+ - - ">="
138
138
  - !ruby/object:Gem::Version
139
139
  version: 0.19.1
140
140
  - !ruby/object:Gem::Dependency
141
141
  name: rake
142
142
  requirement: !ruby/object:Gem::Requirement
143
143
  requirements:
144
- - - '>='
144
+ - - ">="
145
145
  - !ruby/object:Gem::Version
146
146
  version: '0'
147
147
  type: :development
148
148
  prerelease: false
149
149
  version_requirements: !ruby/object:Gem::Requirement
150
150
  requirements:
151
- - - '>='
151
+ - - ">="
152
152
  - !ruby/object:Gem::Version
153
153
  version: '0'
154
154
  - !ruby/object:Gem::Dependency
155
155
  name: heroku
156
156
  requirement: !ruby/object:Gem::Requirement
157
157
  requirements:
158
- - - '>='
158
+ - - ">="
159
159
  - !ruby/object:Gem::Version
160
160
  version: '0'
161
161
  type: :development
162
162
  prerelease: false
163
163
  version_requirements: !ruby/object:Gem::Requirement
164
164
  requirements:
165
- - - '>='
165
+ - - ">="
166
166
  - !ruby/object:Gem::Version
167
167
  version: '0'
168
168
  - !ruby/object:Gem::Dependency
169
169
  name: foreman
170
170
  requirement: !ruby/object:Gem::Requirement
171
171
  requirements:
172
- - - '>='
172
+ - - ">="
173
173
  - !ruby/object:Gem::Version
174
174
  version: '0'
175
175
  type: :development
176
176
  prerelease: false
177
177
  version_requirements: !ruby/object:Gem::Requirement
178
178
  requirements:
179
- - - '>='
179
+ - - ">="
180
180
  - !ruby/object:Gem::Version
181
181
  version: '0'
182
182
  - !ruby/object:Gem::Dependency
183
183
  name: racksh
184
184
  requirement: !ruby/object:Gem::Requirement
185
185
  requirements:
186
- - - '>='
186
+ - - ">="
187
187
  - !ruby/object:Gem::Version
188
188
  version: '0'
189
189
  type: :development
190
190
  prerelease: false
191
191
  version_requirements: !ruby/object:Gem::Requirement
192
192
  requirements:
193
- - - '>='
193
+ - - ">="
194
194
  - !ruby/object:Gem::Version
195
195
  version: '0'
196
196
  - !ruby/object:Gem::Dependency
197
197
  name: coffeelint
198
198
  requirement: !ruby/object:Gem::Requirement
199
199
  requirements:
200
- - - '>='
200
+ - - ">="
201
201
  - !ruby/object:Gem::Version
202
202
  version: '0'
203
203
  type: :development
204
204
  prerelease: false
205
205
  version_requirements: !ruby/object:Gem::Requirement
206
206
  requirements:
207
- - - '>='
207
+ - - ">="
208
208
  - !ruby/object:Gem::Version
209
209
  version: '0'
210
210
  - !ruby/object:Gem::Dependency
211
211
  name: haml-lint
212
212
  requirement: !ruby/object:Gem::Requirement
213
213
  requirements:
214
- - - '>='
214
+ - - ">="
215
215
  - !ruby/object:Gem::Version
216
216
  version: '0'
217
217
  type: :development
218
218
  prerelease: false
219
219
  version_requirements: !ruby/object:Gem::Requirement
220
220
  requirements:
221
- - - '>='
221
+ - - ">="
222
222
  - !ruby/object:Gem::Version
223
223
  version: '0'
224
224
  description: Sabisu is a dashboard for the monitoring framework Sensu. It is powered
@@ -233,6 +233,8 @@ extra_rdoc_files:
233
233
  files:
234
234
  - LICENSE
235
235
  - README.md
236
+ - bin/sabisu
237
+ - lib/sabisu.rb
236
238
  - lib/sabisu/config.rb
237
239
  - lib/sabisu/event.rb
238
240
  - lib/sabisu/public/css/base.css
@@ -242,7 +244,7 @@ files:
242
244
  - lib/sabisu/public/fonts/glyphicons-halflings-regular.svg
243
245
  - lib/sabisu/public/fonts/glyphicons-halflings-regular.ttf
244
246
  - lib/sabisu/public/fonts/glyphicons-halflings-regular.woff
245
- - lib/sabisu/public/js/sabisu.js
247
+ - lib/sabisu/public/js/md5.js
246
248
  - lib/sabisu/public/js/typeahead.js
247
249
  - lib/sabisu/routes/api.rb
248
250
  - lib/sabisu/routes/client.rb
@@ -255,8 +257,6 @@ files:
255
257
  - lib/sabisu/templates/layout.haml
256
258
  - lib/sabisu/templates/login.haml
257
259
  - lib/sabisu/version.rb
258
- - lib/sabisu.rb
259
- - bin/sabisu
260
260
  homepage: http://sabisuapp.org
261
261
  licenses:
262
262
  - Apache License v2
@@ -267,17 +267,17 @@ require_paths:
267
267
  - lib
268
268
  required_ruby_version: !ruby/object:Gem::Requirement
269
269
  requirements:
270
- - - '>='
270
+ - - ">="
271
271
  - !ruby/object:Gem::Version
272
272
  version: 2.0.0
273
273
  required_rubygems_version: !ruby/object:Gem::Requirement
274
274
  requirements:
275
- - - '>='
275
+ - - ">="
276
276
  - !ruby/object:Gem::Version
277
277
  version: '0'
278
278
  requirements: []
279
279
  rubyforge_project:
280
- rubygems_version: 2.0.6
280
+ rubygems_version: 2.4.5.1
281
281
  signing_key:
282
282
  specification_version: 4
283
283
  summary: A sensu dashboard powered by Cloudant
@@ -1,893 +0,0 @@
1
- (function() {
2
- var sabisu,
3
- __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
4
-
5
- sabisu = angular.module('sabisu', []);
6
-
7
- sabisu.config(function($locationProvider) {
8
- return $locationProvider.html5Mode(true);
9
- });
10
-
11
- sabisu.filter('slice', function() {
12
- return function(arr, start, end) {
13
- return arr.slice(start, end);
14
- };
15
- });
16
-
17
- sabisu.filter('joinBy', function() {
18
- return function(input, delimiter) {
19
- return (input || []).join(delimiter || ',');
20
- };
21
- });
22
-
23
- sabisu.controller('eventsController', function($scope, $log, $location, $filter, $sce, eventsFactory, stashesFactory) {
24
- $scope.first_search = true;
25
- $scope.alt_pressed = false;
26
- $scope.checks = [];
27
- $scope.clients = [];
28
- $scope.events = [];
29
- $scope.event_fields = [];
30
- $scope.event_fields_custom = [];
31
- $scope.event_fields_facet = [];
32
- $scope.event_fields_int = [];
33
- $scope.event_fields_name = [];
34
- $scope.events_spin = false;
35
- $scope.showAll = false;
36
- $scope.bulk = 'show';
37
- $scope.isActive = true;
38
- $scope.showDetails = [];
39
- $scope.previous_events_ranges = {};
40
- $scope.previous_events_counts = {};
41
- $scope.previous_events_events = {};
42
- $(window).on('focus', function() {
43
- $scope.isActive = true;
44
- $scope.updateEvents();
45
- return $scope.changes();
46
- });
47
- $(window).on('blur', function() {
48
- return $scope.isActive = false;
49
- });
50
- $(window).keydown(function(evt) {
51
- if (evt.which === 18) {
52
- return $scope.alt_pressed = true;
53
- }
54
- });
55
- $(window).keyup(function(evt) {
56
- if (evt.which === 18) {
57
- return $scope.alt_pressed = false;
58
- }
59
- });
60
- if ($location.search().query != null) {
61
- $scope.search_field = $location.search().query;
62
- $scope.search = $location.search().query;
63
- } else {
64
- $scope.search_field = '';
65
- $scope.search = '';
66
- }
67
- if ($location.search().sort != null) {
68
- $scope.sort_field = $location.search().sort;
69
- $scope.sort = $location.search().sort;
70
- } else {
71
- $scope.sort = '-age';
72
- $scope.sort_field = '-age';
73
- }
74
- if ($location.search().limit != null) {
75
- $scope.limit = $location.search().limit;
76
- $scope.limit_field = $location.search().limit;
77
- } else {
78
- $scope.limit = '50';
79
- $scope.limit_field = '50';
80
- }
81
- if ($location.search().showAll != null) {
82
- $scope.showAll = $location.search().showAll;
83
- $log.info($scope.showAll);
84
- }
85
- $scope.updateEventFields = function() {
86
- return eventsFactory.event_fields().success(function(data, status, headers, config) {
87
- var defaults, field, _i, _len, _ref, _ref1, _results;
88
- defaults = ['client', 'check', 'status', 'state_change', 'occurrence', 'issued', 'output'];
89
- $scope.event_fields = data;
90
- _ref = $scope.event_fields;
91
- _results = [];
92
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
93
- field = _ref[_i];
94
- $scope.event_fields_name.push(field.name);
95
- if (field.type === 'int') {
96
- $scope.event_fields_int.push(field.name);
97
- $scope.event_fields_int.push('-' + field.name);
98
- }
99
- if (field.facet === true) {
100
- $scope.event_fields_facet.push(field.name);
101
- }
102
- if (_ref1 = field.name, __indexOf.call(defaults, _ref1) < 0) {
103
- _results.push($scope.event_fields_custom.push(field));
104
- } else {
105
- _results.push(void 0);
106
- }
107
- }
108
- return _results;
109
- }).error(function(data, status, headers, config) {
110
- return alert("Failed to get fields");
111
- });
112
- };
113
- $scope.updateStashes = function() {
114
- return stashesFactory.stashes().success(function(data, status, headers, config) {
115
- var check, client, event, parts, stash, stashes, _base, _base1, _i, _j, _k, _len, _len1, _len2, _ref, _ref1;
116
- stashes = [];
117
- for (_i = 0, _len = data.length; _i < _len; _i++) {
118
- stash = data[_i];
119
- if (stash['path'].match(/^silence\//)) {
120
- stashes.push(stash);
121
- }
122
- }
123
- $scope.stashes = stashes;
124
- _ref = $scope.stashes;
125
- for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
126
- stash = _ref[_j];
127
- parts = stash['path'].split('/', 3);
128
- client = parts[1];
129
- if (parts.length > 2) {
130
- check = parts[2];
131
- } else {
132
- check = null;
133
- }
134
- _ref1 = $scope.events;
135
- for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
136
- event = _ref1[_k];
137
- if ((_base = event.client).silenced == null) {
138
- _base.silenced = false;
139
- }
140
- if ((_base1 = event.check).silenced == null) {
141
- _base1.silenced = false;
142
- }
143
- if (client === event.client.name) {
144
- if (check === null) {
145
- event.client.silenced = true;
146
- event.client.silence_stash = stash;
147
- break;
148
- } else {
149
- if (check === event.check.name) {
150
- event.check.silenced = true;
151
- event.check.silence_stash = stash;
152
- break;
153
- }
154
- }
155
- }
156
- }
157
- }
158
- $('.close_popover').click(function() {
159
- return $scope.closePopovers();
160
- });
161
- $('body').on('click', function(e) {
162
- return $('[data-toggle="popover"]').each(function() {
163
- if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
164
- return $(this).popover('hide');
165
- }
166
- });
167
- });
168
- return $('.glyphicon-question-sign').tooltip();
169
- });
170
- };
171
- $scope.closePopovers = function() {
172
- return $('.silenceBtn').popover('hide');
173
- };
174
- $scope.createSilenceDetails = function(client, check) {
175
- if (check == null) {
176
- check = null;
177
- }
178
- $scope.silencePath = client;
179
- if (check) {
180
- return $scope.silencePath += '/' + check;
181
- }
182
- };
183
- $scope.updateSilenceDetails = function(stash) {
184
- var check, client, parts;
185
- parts = stash['path'].split('/', 3);
186
- client = parts[1];
187
- check = null;
188
- if (parts.length > 2) {
189
- check = parts[2];
190
- }
191
- $scope.silencePath = client;
192
- if (check) {
193
- $scope.silencePath += '/' + check;
194
- }
195
- if (stash['content']['timestamp']) {
196
- $scope.silenceCreated = $filter('date')(stash['content']['timestamp'] * 1000, 'short');
197
- }
198
- $scope.silenceOwner = stash['content']['owner'];
199
- if (stash['content']['expiration'] === 'resolve') {
200
- $scope.silenceExpires = 'On resolve';
201
- $scope.silenceExpirationClass = 'success';
202
- } else if (stash['content']['expiration'] === 'never') {
203
- $scope.silenceExpires = 'Never';
204
- $scope.silenceExpirationClass = 'danger';
205
- } else if ((stash['expire'] != null) && stash['expire'] !== -1) {
206
- $scope.silenceExpires = moment.unix(parseInt(stash['content']['timestamp']) + parseInt(stash['expire'])).fromNow();
207
- $scope.silenceExpirationClass = 'warning';
208
- }
209
- if (stash['content']['reason'] != null) {
210
- return $scope.silenceReason = stash['content']['reason'];
211
- }
212
- };
213
- $scope.saveSilence = function() {
214
- var expiration, owner, re, reason, stash, timerToSec, timer_val, valid;
215
- valid = true;
216
- owner = $('#owner').val();
217
- if (owner === '') {
218
- $('.silence_owner').removeClass('has-success');
219
- $('.silence_owner').addClass('has-error');
220
- valid = false;
221
- } else {
222
- $('.silence_owner').removeClass('has-error');
223
- $('.silence_owner').addClass('has-success');
224
- }
225
- reason = $('#reason').val();
226
- if (reason === '') {
227
- $('.silence_reason').removeClass('has-success');
228
- $('.silence_reason').addClass('has-error');
229
- valid = false;
230
- } else {
231
- $('.silence_reason').removeClass('has-error');
232
- $('.silence_reason').addClass('has-success');
233
- }
234
- timer_val = $('#timer_val').val();
235
- expiration = $('input[name=expiration]:checked', '#silence_form').val();
236
- if (expiration === 'timer') {
237
- re = new RegExp('^\\d*(m|h|d|w)$');
238
- if (re.test(timer_val)) {
239
- $('.silence_timer_val').removeClass('has-error');
240
- $('.silence_timer_val').addClass('has-success');
241
- } else {
242
- $('.silence_timer_val').removeClass('has-success');
243
- $('.silence_timer_val').addClass('has-error');
244
- valid = false;
245
- }
246
- } else {
247
- $('.silence_timer_val').removeClass('has-error');
248
- $('.silence_timer_val').removeClass('has-success');
249
- }
250
- timerToSec = function(val) {
251
- var conversion, q, quantity, u, unit;
252
- q = new RegExp('^\\d*');
253
- u = new RegExp('[a-z]$');
254
- conversion = {
255
- m: 60,
256
- h: 60 * 60,
257
- d: 60 * 60 * 24,
258
- w: 60 * 60 * 24 * 7
259
- };
260
- quantity = val.match(q)[0];
261
- unit = val.match(u)[0];
262
- return quantity * conversion[unit];
263
- };
264
- if (valid) {
265
- stash = {};
266
- stash['path'] = "silence/" + $scope.silencePath;
267
- stash['content'] = {};
268
- stash['content']['timestamp'] = Math.round((new Date().getTime()) / 1000);
269
- stash['content']['owner'] = owner;
270
- stash['content']['reason'] = reason;
271
- stash['content']['expiration'] = expiration;
272
- if (expiration === 'timer') {
273
- stash['expire'] = timerToSec(timer_val);
274
- }
275
- return stashesFactory.saveStash(stash).success(function(data, status, headers, config) {
276
- $scope.updateStashes();
277
- owner = $('#owner').val();
278
- $('.silence_owner').removeClass('has-success');
279
- $('.silence_owner').removeClass('has-error');
280
- reason = $('#reason').val();
281
- $('.silence_reason').removeClass('has-success');
282
- $('.silence_reason').removeClass('has-error');
283
- timer_val = $('#timer_val').val();
284
- expiration = $('input[name=expiration]:checked', '#silence_form').val();
285
- $('.silence_timer_val').removeClass('has-error');
286
- $('.silence_timer_val').removeClass('has-success');
287
- return $('#silence_window').modal('hide');
288
- }).error(function(data, status, headers, config) {
289
- return alert("Failed to silence: (" + status + ") " + data);
290
- });
291
- }
292
- };
293
- $scope.deleteSilence = function(path) {
294
- return stashesFactory.deleteStash(path).success(function(data, status, headers, config) {
295
- $scope.updateStashes();
296
- return $scope.closePopovers();
297
- }).error(function(data, status, headers, config) {
298
- return alert("Failed to delete silence");
299
- });
300
- };
301
- $scope.resolveEvent = function(client, check) {
302
- return eventsFactory.resolveEvent(client, check).success(function(data, status, headers, config) {
303
- return $scope.updateEvents();
304
- }).error(function(data, status, headers, config) {
305
- return alert("Faild to resolve event: " + client + "/" + check);
306
- });
307
- };
308
- $scope.updateParams = function() {
309
- $scope.search = $scope.search_field;
310
- $scope.sort = $scope.sort_field;
311
- $scope.limit = $scope.limit_field;
312
- $location.search('query', $scope.search);
313
- $location.search('sort', $scope.sort);
314
- $location.search('limit', $scope.limit);
315
- return $scope.updateEvents();
316
- };
317
- $scope.format_attr_value = function(event, key, path) {
318
- var field, p, val, _i, _j, _len, _len1, _ref;
319
- path = path.split('.');
320
- val = event;
321
- for (_i = 0, _len = path.length; _i < _len; _i++) {
322
- p = path[_i];
323
- if (p in val) {
324
- val = val[p];
325
- } else {
326
- val = null;
327
- break;
328
- }
329
- }
330
- if (val === void 0 || val === null) {
331
- val = 'n/a';
332
- } else if ($scope.typeIsArray(val)) {
333
- val = $filter('joinBy')(val, ', ');
334
- } else if (String(val).match('^[0-9]{13}$')) {
335
- val = $filter('date')(val, 'short');
336
- } else {
337
- _ref = $scope.event_fields;
338
- for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
339
- field = _ref[_j];
340
- if (field.name === key && field.type === 'url') {
341
- val = "<a href='" + val + "'>goto</a>";
342
- }
343
- }
344
- }
345
- return $sce.trustAsHtml(String(val));
346
- };
347
- $scope.getEventAttributes = function(event) {
348
- var a, attr, i, side, _i, _j, _len, _len1, _ref, _ref1;
349
- attr = {
350
- 'left': [['issued', 'check.issued'], ['interval', 'check.interval'], ['occurrences', 'occurrences']].concat((function() {
351
- var _i, _len, _ref, _results;
352
- _ref = $scope.event_fields_custom;
353
- _results = [];
354
- for (_i = 0, _len = _ref.length; _i < _len; _i += 2) {
355
- i = _ref[_i];
356
- _results.push([i.name, i.path]);
357
- }
358
- return _results;
359
- })()),
360
- 'right': [['state change', 'rel_time'], ['subscribers', 'check.subscribers'], ['handlers', 'check.handlers']].concat((function() {
361
- var _i, _len, _ref, _results;
362
- _ref = $scope.event_fields_custom.slice(1);
363
- _results = [];
364
- for (_i = 0, _len = _ref.length; _i < _len; _i += 2) {
365
- i = _ref[_i];
366
- _results.push([i.name, i.path]);
367
- }
368
- return _results;
369
- })())
370
- };
371
- _ref = ['left', 'right'];
372
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
373
- side = _ref[_i];
374
- _ref1 = attr[side];
375
- for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
376
- a = _ref1[_j];
377
- a[1] = $scope.format_attr_value(event, a[0], a[1]);
378
- }
379
- }
380
- return attr;
381
- };
382
- $scope.appendQuery = function(val, type, quote) {
383
- var q;
384
- if (type == null) {
385
- type = null;
386
- }
387
- if (quote == null) {
388
- quote = true;
389
- }
390
- q = '';
391
- if ($scope.search.length > 0) {
392
- if ($scope.alt_pressed) {
393
- q += ' AND NOT ';
394
- } else {
395
- q += ' AND ';
396
- }
397
- } else {
398
- if ($scope.alt_pressed) {
399
- q += '*:* AND NOT ';
400
- }
401
- }
402
- if (type != null) {
403
- q += type + ':';
404
- }
405
- if (quote) {
406
- q += "\"" + val + "\"";
407
- } else {
408
- q += "" + val;
409
- }
410
- $scope.search += q;
411
- $scope.search_field = $scope.search;
412
- $location.search('query', $scope.search);
413
- return $scope.updateEvents();
414
- };
415
- $scope.updateEvents = function() {
416
- if ($scope.first_search) {
417
- $scope.events_spin = true;
418
- }
419
- $scope.first_search = false;
420
- return eventsFactory.searchEvents($scope.search, $scope.sort, $scope.limit, $scope.event_fields_int).success(function(data, status, headers, config) {
421
- var check, client, color, event, events, field, id, k, parts, stash, stats, statuses, v, _base, _base1, _i, _j, _len, _len1, _ref, _ref1, _ref2, _ref3;
422
- color = ['success', 'warning', 'danger', 'info'];
423
- status = ['OK', 'Warning', 'Critical', 'Unknown'];
424
- events = [];
425
- if ('bookmark' in data) {
426
- $scope.bookmark = data['bookmark'];
427
- }
428
- if ('count' in data) {
429
- $scope.count = data['count'];
430
- }
431
- if ('ranges' in data && !angular.equals($scope.previous_events_ranges, data['ranges']['status'])) {
432
- statuses = data['ranges']['status'];
433
- $scope.previous_events_ranges = statuses;
434
- $('#stats_status').find('#totals').find('.label-warning').text("Warning: " + statuses['Warning']);
435
- $('#stats_status').find('#totals').find('.label-danger').text("Critical: " + statuses['Critical']);
436
- $('#stats_status').find('#totals').find('.label-info').text("Unknown: " + statuses['Unknown']);
437
- }
438
- if ('counts' in data && !angular.equals($scope.previous_events_counts, data['counts'])) {
439
- $scope.previous_events_counts = data['counts'];
440
- stats = {};
441
- for (field in data['counts']) {
442
- stats[field] = [];
443
- _ref = data['counts'][field];
444
- for (k in _ref) {
445
- v = _ref[k];
446
- stats[field].push([k, v]);
447
- }
448
- stats[field].sort(function(a, b) {
449
- return a[1] - b[1];
450
- }).reverse();
451
- }
452
- $scope.stats = stats;
453
- }
454
- if ('rows' in data && !angular.equals($scope.previous_events_events, data.rows)) {
455
- $scope.previous_events_events = angular.copy(data.rows);
456
- _ref1 = data.rows;
457
- for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
458
- event = _ref1[_i];
459
- event = event.doc.event;
460
- id = "" + event.client.name + "/" + event.check.name;
461
- event.id = CryptoJS.MD5(id).toString(CryptoJS.enc.Base64);
462
- if ((_ref2 = event.id, __indexOf.call($scope.showDetails, _ref2) >= 0) || $scope.showAll === 'true') {
463
- event.showdetails = 'in';
464
- } else {
465
- event.showdetails = '';
466
- }
467
- event.color = color[event.check.status];
468
- event.wstatus = status[event.check.status];
469
- if (event.check.state_change === null || event.check.state_change === void 0) {
470
- event.rel_time = 'n/a';
471
- } else {
472
- event.rel_time = moment.unix(event.check.state_change).fromNow();
473
- }
474
- event.check.issued = event.check.issued * 1000;
475
- if (event.check.state_change != null) {
476
- event.check.state_change = event.check.state_change * 1000;
477
- }
478
- if ((_base = event.client).silenced == null) {
479
- _base.silenced = false;
480
- }
481
- if ((_base1 = event.check).silenced == null) {
482
- _base1.silenced = false;
483
- }
484
- if ($scope.stashes != null) {
485
- _ref3 = $scope.stashes;
486
- for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) {
487
- stash = _ref3[_j];
488
- parts = stash['path'].split('/', 3);
489
- client = parts[1];
490
- if (parts.length > 2) {
491
- check = parts[2];
492
- } else {
493
- check = null;
494
- }
495
- if (client === event.client.name) {
496
- if (check === null) {
497
- event.client.silenced = true;
498
- event.client.silence_stash = stash;
499
- } else if (check === event.check.name) {
500
- event.check.silenced = true;
501
- event.check.silence_stash = stash;
502
- }
503
- }
504
- }
505
- }
506
- event.attributes = $scope.getEventAttributes(event);
507
- events.push(event);
508
- }
509
- $scope.events_spin = false;
510
- if (!angular.equals($scope.events, events)) {
511
- $scope.events = events;
512
- $scope.updateStashes();
513
- }
514
- }
515
- $scope.events_spin = false;
516
- return $('#corner_status').text("Last Update: " + $filter('date')(Date.now(), 'mediumTime'));
517
- });
518
- };
519
- $scope.updateEventFields();
520
- $scope.updateEvents();
521
- $scope.changes = function() {
522
- var params;
523
- $log.info("STARTING _CHANGES FEED");
524
- params = {
525
- feed: 'longpoll',
526
- heartbeat: 10000
527
- };
528
- if ($scope.last_seq != null) {
529
- params['since'] = $scope.last_seq;
530
- return eventsFactory.changes(params).success(function(data, status, headers, config) {
531
- $scope.last_seq = data['last_seq'];
532
- $scope.updateEvents();
533
- if ($scope.isActive === true) {
534
- return $scope.changes();
535
- }
536
- }).error(function(data, status, headers, config) {
537
- $log.error("failed changes request (" + status + ") - " + data);
538
- if ($scope.isActive === true) {
539
- return $scope.changes();
540
- }
541
- });
542
- }
543
- };
544
- $scope.get_sequence = function() {
545
- return eventsFactory.last_sequence().success(function(data, status, headers, config) {
546
- $scope.last_seq = data['last_seq'];
547
- $log.info($scope.last_seq);
548
- return $scope.changes();
549
- });
550
- };
551
- $scope.get_sequence();
552
- $scope.bulkToggleDetails = function() {
553
- var action, event, _i, _j, _len, _len1, _ref, _ref1, _results;
554
- if ($scope.bulk === 'show') {
555
- action = 'show';
556
- $scope.showDetails = [];
557
- _ref = $scope.events;
558
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
559
- event = _ref[_i];
560
- $scope.showDetails.push(event.id);
561
- }
562
- } else {
563
- action = 'hide';
564
- $scope.showDetails = [];
565
- }
566
- _ref1 = $scope.events;
567
- _results = [];
568
- for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
569
- event = _ref1[_j];
570
- _results.push($("#" + event.id).collapse(action));
571
- }
572
- return _results;
573
- };
574
- $('.collapse').on('hide.bs.collapse', function() {
575
- if ($scope.showDetails.length === 0) {
576
- return $scope.bulk = 'show';
577
- }
578
- });
579
- $('.collapse').on('show.bs.collapse', function() {
580
- if ($scope.showDetails.length > 0) {
581
- return $scope.bulk = 'hide';
582
- }
583
- });
584
- $scope.toggleDetails = function(id) {
585
- var i;
586
- if (!$("#" + id).hasClass('in')) {
587
- $("#" + id).collapse('show');
588
- if ($scope.showDetails.indexOf(id) === -1) {
589
- $scope.showDetails.push(id);
590
- }
591
- $("#" + id).parent().find('.toggleBtnIcon').removeClass('glyphicon-collapse-down');
592
- return $("#" + id).parent().find('.toggleBtnIcon').addClass('glyphicon-collapse-up');
593
- } else {
594
- $("#" + id).collapse('hide');
595
- i = $scope.showDetails.indexOf(id);
596
- if (i !== -1) {
597
- $scope.showDetails.splice(i, 1);
598
- }
599
- $("#" + id).parent().find('.toggleBtnIcon').removeClass('glyphicon-collapse-up');
600
- return $("#" + id).parent().find('.toggleBtnIcon').addClass('glyphicon-collapse-down');
601
- }
602
- };
603
- $scope.togglePopover = function() {
604
- $(this).popover();
605
- return $(this).popover('toggle');
606
- };
607
- $scope.typeIsArray = function(value) {
608
- return value && typeof value === 'object' && value instanceof Array && typeof value.length === 'number' && typeof value.splice === 'function' && !(value.propertyIsEnumerable('length'));
609
- };
610
-
611
- /* Keyboard Shortcuts */
612
- Mousetrap.bind('?', function() {
613
- $log.info('showing shortcuts');
614
- return $("#keyboard_shortcuts").modal('show');
615
- }, 'keyup');
616
- Mousetrap.bind('.', function() {
617
- return $('#search_input').focus();
618
- }, 'keyup');
619
- Mousetrap.bind('s', function() {
620
- $('#sort').focus();
621
- return $('#sort').click();
622
- }, 'keyup');
623
- return Mousetrap.bind('enter', function() {
624
- return $scope.updateParams();
625
- }, 'keyup');
626
- });
627
-
628
- sabisu.directive('searchTypeahead', function($log, $window, $filter, $timeout, eventsFactory) {
629
- return function(scope, element, attrs) {
630
- var all_but_last_clause, at_bool, at_key, at_none, at_val, clause_char_list, current_clause, el, whitespace_at_end;
631
- clause_char_list = "a-zA-Z0-9_\\-\\?\\*\\+\\~\\.\\[\\]\\{\\}\\^\"";
632
- el = angular.element(element);
633
- current_clause = function() {
634
- var lastIndex;
635
- lastIndex = el.current_search_string.lastIndexOf(" ");
636
- return el.current_search_string.substring(lastIndex + 1).split(':');
637
- };
638
- all_but_last_clause = function() {
639
- var a, lastIndex;
640
- lastIndex = el.current_search_string.lastIndexOf(" ");
641
- a = el.current_search_string.substring(0, lastIndex);
642
- if (a.length > 0) {
643
- a = a + ' ';
644
- }
645
- return a;
646
- };
647
- whitespace_at_end = function() {
648
- var m;
649
- m = el.current_search_string.match(RegExp(" $"));
650
- return m != null;
651
- };
652
- at_none = function() {
653
- var c, quote_count;
654
- c = current_clause();
655
- quote_count = 0;
656
- if (c.length >= 2) {
657
- quote_count = c[1].split('"').length - 1;
658
- }
659
- return el.current_search_string.slice(-1) === '"' && quote_count === 2;
660
- };
661
- at_val = function() {
662
- return (current_clause() != null) && current_clause().length === 2 && !whitespace_at_end();
663
- };
664
- at_bool = function() {
665
- if (all_but_last_clause().match(RegExp("(AND|AND NOT|OR|OR NOT) $"))) {
666
- return false;
667
- }
668
- if (all_but_last_clause() === '') {
669
- return false;
670
- }
671
- if ((current_clause() != null) && current_clause().length === 2 && whitespace_at_end()) {
672
- return true;
673
- }
674
- if (current_clause() !== null) {
675
- if ('AND NOT'.match(RegExp("^" + (current_clause()[0]))) != null) {
676
- return true;
677
- }
678
- if ('OR NOT'.match(RegExp("^" + (current_clause()[0]))) != null) {
679
- return true;
680
- }
681
- }
682
- return false;
683
- };
684
- at_key = function() {
685
- return !at_bool() && !at_val() && !at_none();
686
- };
687
- el.typeahead({
688
- minLength: 0,
689
- highlight: true,
690
- hint: true
691
- }, {
692
- name: 'keys',
693
- displayKey: 'name',
694
- source: function(search_string, cb) {
695
- var data, dd, indent, key, search_word, search_word_clean, sel_start;
696
- el.current_search_string = search_string;
697
- search_word = current_clause() ? current_clause().slice(-1)[0] : '';
698
- if (at_key() && whitespace_at_end()) {
699
- search_word = '';
700
- }
701
- search_word_clean = search_word.trim().replace(/"/, '');
702
- sel_start = element[0].selectionStart || 0;
703
- if (whitespace_at_end()) {
704
- indent = Math.max(0, sel_start) * 0.535;
705
- } else {
706
- if (current_clause().length > 1) {
707
- key = current_clause()[0].length + 1;
708
- } else {
709
- key = 0;
710
- }
711
- indent = Math.max(0, sel_start - (search_word.length + key)) * 0.535;
712
- }
713
- dd = angular.element("#" + element[0].id + " ~ .tt-dropdown-menu");
714
- dd[0].style.left = "" + indent + "em";
715
- if (search_string.length === 0) {
716
- angular.element(".tt-hint").hide();
717
- } else {
718
- angular.element(".tt-hint").show();
719
- }
720
- if (at_val()) {
721
- key = current_clause()[0];
722
- if (scope.stats[key]) {
723
- data = [];
724
- angular.forEach(scope.stats[key], function(v, k) {
725
- if (v[0].trim() !== "" && v[0].indexOf(search_word_clean) === 0) {
726
- return data.push({
727
- name: "" + key + ":" + v[0]
728
- });
729
- }
730
- });
731
- data = $filter('orderBy')(data, 'name');
732
- return cb(data);
733
- } else {
734
- return cb([]);
735
- }
736
- } else if (at_bool()) {
737
- return cb([
738
- {
739
- name: 'AND'
740
- }, {
741
- name: 'AND NOT'
742
- }, {
743
- name: 'OR'
744
- }, {
745
- name: 'OR NOT'
746
- }
747
- ]);
748
- } else if (at_none()) {
749
- return cb([]);
750
- } else {
751
- return eventsFactory.event_fields().success(function(data, status, headers, config) {
752
- var field, fields, _i, _len;
753
- fields = [];
754
- for (_i = 0, _len = data.length; _i < _len; _i++) {
755
- field = data[_i];
756
- if (field.index) {
757
- fields.push(field);
758
- }
759
- }
760
- if (search_word_clean.length > 0) {
761
- fields = $.grep(fields, function(n, i) {
762
- return n.name.indexOf(search_word_clean) === 0;
763
- });
764
- }
765
- fields = $filter('orderBy')(fields, 'name');
766
- return cb(fields);
767
- });
768
- }
769
- }
770
- });
771
- el.on('focus', function() {
772
- var curval;
773
- curval = scope.search_field;
774
- el.typeahead('val', 'c').typeahead('open');
775
- return el.typeahead('val', curval).typeahead('open');
776
- });
777
- el.on('typeahead:selected', function($e, datum) {
778
- var val;
779
- if (at_val()) {
780
- val = datum.name.split(':');
781
- el.typeahead('val', all_but_last_clause() + val[0] + ':"' + val[1] + '" ');
782
- } else if (at_key()) {
783
- el.typeahead('val', all_but_last_clause() + datum.name + ':');
784
- } else {
785
- el.typeahead('val', all_but_last_clause() + datum.name + ' ');
786
- }
787
- scope.search_field = el.typeahead('val');
788
- return $timeout(function() {
789
- var curval;
790
- curval = el.typeahead('val');
791
- el.typeahead('val', 'c').typeahead('open');
792
- return el.typeahead('val', curval).typeahead('open');
793
- }, 100);
794
- });
795
- el.on('typeahead:autocompleted', function($e, datum) {
796
- var val;
797
- if (at_key()) {
798
- el.typeahead('val', all_but_last_clause() + datum.name + ':');
799
- } else if (at_val()) {
800
- val = datum.name.split(':');
801
- el.typeahead('val', all_but_last_clause() + val[0] + ':"' + val[1] + '" ');
802
- } else {
803
- el.typeahead('val', all_but_last_clause() + datum.name + ' ');
804
- }
805
- scope.search_field = el.typeahead('val');
806
- return el.typeahead('open');
807
- });
808
- return el.on('typeahead:cursorchanged', function($e, datum, dsName) {
809
- angular.element(".tt-input").val(all_but_last_clause() + datum.name);
810
- return angular.element(".tt-hint").val("");
811
- });
812
- };
813
- });
814
-
815
- sabisu.factory('eventsFactory', function($log, $http) {
816
- var factory;
817
- factory = {};
818
- factory.searchEvents = function(search_query, sort, limit, ints) {
819
- if (sort === 'age') {
820
- sort = 'state_change';
821
- }
822
- if (sort === '-age') {
823
- sort = '-state_change';
824
- }
825
- if (__indexOf.call(ints, sort) < 0) {
826
- sort = sort + '<string>';
827
- }
828
- sort = "[\"" + sort + "\"]";
829
- if (search_query === '') {
830
- search_query = '*:*';
831
- }
832
- return $http({
833
- method: 'GET',
834
- url: '/api/events/search',
835
- params: {
836
- query: search_query,
837
- limit: limit,
838
- sort: sort
839
- }
840
- });
841
- };
842
- factory.resolveEvent = function(client, check) {
843
- return $http({
844
- method: 'POST',
845
- url: '/sensu/resolve',
846
- data: {
847
- client: client,
848
- check: check
849
- }
850
- });
851
- };
852
- factory.changes = function(params) {
853
- return $http({
854
- method: 'GET',
855
- url: '/api/events/changes',
856
- params: params
857
- });
858
- };
859
- factory.last_sequence = function() {
860
- return $http({
861
- method: 'GET',
862
- url: '/api/events/changes',
863
- params: {
864
- limit: 1,
865
- descending: true
866
- }
867
- });
868
- };
869
- factory.event_fields = function() {
870
- return $http({
871
- method: 'GET',
872
- url: '/api/configuration/fields'
873
- });
874
- };
875
- return factory;
876
- });
877
-
878
- sabisu.factory('stashesFactory', function($log, $http) {
879
- var factory;
880
- factory = {};
881
- factory.stashes = function() {
882
- return $http.get('/sensu/stashes');
883
- };
884
- factory.saveStash = function(stash) {
885
- return $http.post("/sensu/stashes", stash);
886
- };
887
- factory.deleteStash = function(path) {
888
- return $http["delete"]("/sensu/stashes/" + path);
889
- };
890
- return factory;
891
- });
892
-
893
- }).call(this);