lita-trisul 0.2.0 → 0.2.2

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: f37f66441f766755615d6171a02bd314835bc378
4
- data.tar.gz: b62e5345f70bb1ed4a8c0928050e048197fe93de
3
+ metadata.gz: b7f2e06dac2238e0581b1fdd2f5b6f09f3c7618d
4
+ data.tar.gz: aced36e832fa15704cf1a193da32bdb7844f8da9
5
5
  SHA512:
6
- metadata.gz: 2b31280485d84009056fa31265e5bbf24b8a706c2daa0654aa5b31c2ff2f34b7fe91580effc67ea6782e8276a8894ef3c07d4104a17e52dbe707dc7c76ee159e
7
- data.tar.gz: ec20e2e7eb16e37c544dcf7920fd7927c7c7c7aa4cc8adf88ed6335239236d3af19af6c398887beb7827ff2e05860f9ed6e179f1150a6b048b51a21d7cb59d67
6
+ metadata.gz: 4c71105c636056c788948bc68caf75fb190c0bd501ef06f2d026edc94c4d29eccd0e6211d6ad4028da217a1bb6a5b52da6889e3221a347f9c0168e7e16512141
7
+ data.tar.gz: ec11c9ad6782add50c643240799ca24ed45e7b464f3e1e09bffcc464b35e2bfcf6cb4110ba333aa952c2408efd220641fba3853fcd456ba5acd490f2727489d9
data/Gemfile CHANGED
@@ -3,4 +3,20 @@ source "https://rubygems.org"
3
3
  gem 'rake'
4
4
  gem 'rspec'
5
5
 
6
+ gem "rack-test"
7
+ gem "lita"
8
+ gem "trisulrp"
9
+ gem "ffi-rzmq"
10
+
11
+ # Uncomment to use the HipChat adapter
12
+ gem "builder"
13
+ gem "gerbilcharts"
14
+
15
+ #Uncomment to use the IRC adapter
16
+ #gem "lita-irc"
17
+ #gem "lita-hello"
18
+ # Add handlers to give Lita new functionality.
19
+ # For example:
20
+ #gem "lita-google-images"
21
+
6
22
  gemspec
data/README.md CHANGED
@@ -3,7 +3,9 @@
3
3
  [![Build Status](https://travis-ci.org/kkn1806/lita-trisul.png?branch=master)](https://travis-ci.org/kkn1806/lita-trisul)
4
4
  [![Coverage Status](https://coveralls.io/repos/kkn1806/lita-trisul/badge.png)](https://coveralls.io/r/kkn1806/lita-trisul)
5
5
 
6
- TODO: Add a description of the plugin.
6
+
7
+
8
+ Lita-Trisul is a chat bot for Trisul Network Analytics
7
9
 
8
10
  ## Installation
9
11
 
@@ -20,3 +22,43 @@ TODO: Describe any configuration attributes the plugin exposes.
20
22
  ## Usage
21
23
 
22
24
  TODO: Describe the plugin's features and how to use them.
25
+
26
+
27
+
28
+
29
+ ## Additional instructions
30
+
31
+
32
+ ### Base install
33
+
34
+ 1. Fork and then
35
+ - Ubuntu - `git clone https://github.com/trisulnsm/lita-trisul.git`
36
+ 2. Install ruby
37
+ - Ubuntu - `sudo apt-get install ruby ruby-dev`
38
+ 3. Install Ruby binding for ZMQ - we use this to connect to Trisul domain
39
+ 1. Ubuntu - `sudo apt-get install ruby-ffi-rzmq`
40
+ 4. Install other dependencies
41
+ 1. Ubuntu - `sudo apt-get install build-essential libssl-dev redis-server librsvg2-bin`
42
+ 5. Install bundler and all the gems
43
+ - Ubuntu - `sudo gem install bundler` then `bundle install`
44
+
45
+
46
+
47
+ ### Creating your Chat bot
48
+
49
+
50
+
51
+ 1. Create a new LITA instance
52
+ - `lita new mybotwalle`
53
+ 1. Configure your BOT for HIPCHAT
54
+ - Open : walle/lita_conf and choose a nick
55
+
56
+
57
+
58
+ # There seems to be a bug with gerbil charts
59
+ # To provide a temporary fix against the bug, copy the gerbil.js and brushmetal.css files to the directory to the directory from which the bot is started and then start the bot
60
+ # cp /var/lib/gems/2.3.0/gems/lita-trisul-0.2.0/lib/lita/handlers/gerbil.js .
61
+ # cp /var/lib/gems/2.3.0/gems/lita-trisul-0.2.0/lib/lita/handlers/brushmetal.js .
62
+
63
+
64
+
@@ -0,0 +1,296 @@
1
+ .surfacepanel
2
+ {
3
+ fill: none;
4
+ stroke-width: 1;
5
+ stroke: black;
6
+ }
7
+ .gridlineh
8
+ {
9
+ stroke-width: 0.7;
10
+ stroke: #ccc;
11
+ }
12
+ .gridlinev
13
+ {
14
+ stroke-width: 0.7;
15
+ stroke: #ccc;
16
+ }
17
+ .gridlinesub
18
+ {
19
+ stroke-width: 0.5;
20
+ stroke: #eee;
21
+ }
22
+ .surfaceback
23
+ {
24
+ fill: white;
25
+ stroke: none;
26
+ }
27
+ .axispanel
28
+ {
29
+ fill: #EEEEEE;
30
+ stroke: none;
31
+ }
32
+ .axistickmajor
33
+ {
34
+ stroke-width: 2;
35
+ stroke: black;
36
+ }
37
+ .axistickminor
38
+ {
39
+ stroke-width: 1;
40
+ stroke: black;
41
+ }
42
+ .panel
43
+ {
44
+ fill: white;
45
+ }
46
+
47
+ .legend
48
+ {
49
+ fill: red;
50
+ }
51
+ .x_mk
52
+ {
53
+ fill: yellow;
54
+ fill-opacity: 0.10;
55
+ stroke: gray;
56
+ }
57
+ #ref_mod
58
+ {
59
+ fill: gray;
60
+ fill-opacity: 0.20;
61
+ stroke: none;
62
+ }
63
+ #item0
64
+ {
65
+ stroke: none;
66
+ fill: #2166AC;
67
+ }
68
+ #item1
69
+ {
70
+ stroke: none;
71
+ fill: #4393C3;
72
+ }
73
+ #item2
74
+ {
75
+ stroke: none;
76
+ fill: #92C5DE;
77
+ }
78
+ #item3
79
+ {
80
+ stroke: none;
81
+ fill:#D1E5F0;
82
+ }
83
+ #item4
84
+ {
85
+ stroke: none;
86
+ fill:#D6604D; /*FDDBC7*/
87
+ }
88
+ #item5
89
+ {
90
+ stroke: none;
91
+ fill:#FDDBC7;
92
+ }
93
+ #item6
94
+ {
95
+ stroke: none;
96
+ fill: #2166AC;
97
+ }
98
+ #item7
99
+ {
100
+ stroke: none;
101
+ fill: #4393C3;
102
+ }
103
+ #item8
104
+ {
105
+ stroke: none;
106
+ fill: #92C5DE;
107
+ }
108
+ #item9
109
+ {
110
+ stroke: none;
111
+ fill: #92C5DE;
112
+ }
113
+ #item10
114
+ {
115
+ stroke: none;
116
+ fill: #D1E5F0;
117
+ }
118
+ #lineitem0
119
+ {
120
+ stroke: #2166AC;
121
+ stroke-width: 2;
122
+ }
123
+ #lineitem1
124
+ {
125
+ stroke: #4393C3;
126
+ stroke-width: 2;
127
+ }
128
+ #lineitem2
129
+ {
130
+ stroke:#92C5DE;
131
+ stroke-width: 2;
132
+ }
133
+ #lineitem3
134
+ {
135
+ stroke:#D1E5F0;
136
+ stroke-width: 2;
137
+ }
138
+ #lineitem4
139
+ {
140
+ stroke:#FDDBC7;
141
+ stroke-width: 2;
142
+ }
143
+ #lineitem5
144
+ {
145
+ stroke: #F4A582;
146
+ stroke-width:2;
147
+ }
148
+ #lineitem6
149
+ {
150
+ stroke: #D6604D;
151
+ stroke-width: 2;
152
+ }
153
+ #lineitem7
154
+ {
155
+ stroke: none;
156
+ stroke-width: 2;
157
+ }
158
+ #lineitem8
159
+ {
160
+ stroke: none;
161
+ stroke-width: 2;
162
+ }
163
+ .axislabel
164
+ {
165
+ font-family: monospace;
166
+ font-size: 11px;
167
+ fill: black;
168
+ stroke: none;
169
+ }
170
+
171
+ .axislabelt0
172
+ {
173
+ font-family: monospace;
174
+ font-size: 9px;
175
+ fill: black;
176
+ stroke: none;
177
+ }
178
+ .titletext
179
+ {
180
+ fill: #999;
181
+ stroke:none;
182
+ font-family: Arial, Helvetica, sans-serif;
183
+ font-size: 22px;
184
+ }
185
+ .titlepanel
186
+ {
187
+ fill: none;
188
+ fill-opacity: 0.5;
189
+ }
190
+ .titletool
191
+ {
192
+ fill: #AAA;
193
+ stroke:none;
194
+ font-family: Arial, Helvetica, sans-serif;
195
+ font-size: 10px;
196
+ }
197
+ .legendpanel
198
+ {
199
+ fill: white;
200
+ fill-opacity: 0.6;
201
+ stroke: #ddd;
202
+ }
203
+
204
+ .legendtext
205
+ {
206
+ font-family: Arial,Helvetica,sans-serif;
207
+ font-size: 10px;
208
+ fill: black;
209
+ stroke: none;
210
+ }
211
+ .legendstats
212
+ {
213
+ font-family: monospace;
214
+ font-size: 10px;
215
+ fill: black;
216
+ stroke: none;
217
+ }
218
+
219
+ .elementlabel
220
+ {
221
+ font-family: Arial,Helvetica,sans-serif;
222
+ font-size: 10px;
223
+ fill: black;
224
+ stroke: none;
225
+ }
226
+ .elementlabel_large
227
+ {
228
+ font-family: Arial,Helvetica,sans-serif;
229
+ font-size: 10px;
230
+ fill: black;
231
+ stroke: none;
232
+ }
233
+ .elementlabel_huge
234
+ {
235
+ font-family: Arial,Helvetica,sans-serif;
236
+ font-size: 12px;
237
+ fill: black;
238
+ stroke: none;
239
+ }
240
+ .elementvalue
241
+ {
242
+ font-family: Arial,Helvetica,sans-serif;
243
+ font-size: 10px;
244
+ fill: black;
245
+ stroke: none;
246
+ }
247
+ .elementvalue_large
248
+ {
249
+ font-family: Arial,Helvetica,sans-serif;
250
+ font-size: 10px;
251
+ fill: black;
252
+ stroke: none;
253
+ }
254
+ .elementvalue_huge
255
+ {
256
+ font-family: Arial,Helvetica,sans-serif;
257
+ font-size: 12px;
258
+ fill: black;
259
+ stroke: none;
260
+ }
261
+ .trackerpanel
262
+ {
263
+ fill: white;
264
+ fill-opacity: 0.0;
265
+ }
266
+ .trackerrect
267
+ {
268
+ fill: red;
269
+ fill-opacity: 0.4;
270
+ }
271
+ .trackertextinterval
272
+ {
273
+ font-family: courier;
274
+ font-size: 11px;
275
+ fill: black;
276
+ stroke: none;
277
+ }
278
+ .trackertextfromts
279
+ {
280
+ font-family: courier;
281
+ font-size: 9px;
282
+ fill: black;
283
+ stroke: none;
284
+ }
285
+ .refline
286
+ {
287
+ stroke-width: 1px;
288
+ stroke: red;
289
+ }
290
+ .reflinelabel
291
+ {
292
+ fill: #900;
293
+ stroke:none;
294
+ font-size: 10px;
295
+ font-family: Arial, Helvetica, sans-serif;
296
+ }
@@ -0,0 +1,381 @@
1
+ var SVGDocument = null;
2
+ var SVGRoot = null;
3
+ var SVGViewBox = null;
4
+ var svgns = 'http://www.w3.org/2000/svg';
5
+ var xlinkns = 'http://www.w3.org/1999/xlink';
6
+ var toolTip = null;
7
+ var TrueCoords = null;
8
+ var tipBox = null;
9
+ var tipText = null;
10
+ var tipTitle = null;
11
+ var tipDesc = null;
12
+ var ajaxPE = null;
13
+ var lastElement = null;
14
+ var titleText = '';
15
+ var titleDesc = '';
16
+
17
+ function OpacityDown(mouseover_evt)
18
+ {
19
+ var obj=mouseover_evt.target;
20
+ obj.style.setProperty("opacity","0.5","");
21
+ }
22
+
23
+
24
+ function OpacityUp(mouseout_evt)
25
+ {
26
+ var obj=mouseout_evt.target;
27
+ obj.style.setProperty("opacity","1.0","");
28
+ }
29
+
30
+ function GerbilNavigate()
31
+ {
32
+ window.top.location='/dashboard/show';
33
+ }
34
+
35
+ function parseXMLFromString(text)
36
+ {
37
+ if (typeof DOMParser != "undefined")
38
+ {
39
+ // Mozilla, Firefox, and related browsers
40
+ return (new DOMParser()).parseFromString(text, "application/xml");
41
+ }
42
+ else if (typeof ActiveXObject != "undefined")
43
+ {
44
+ // Internet Explorer.
45
+ var xmlDOM = new ActiveXObject("Microsoft.XMLDOM");
46
+ var doc = xmlDOM.newDocument();
47
+ doc.loadXML(text);
48
+ return doc.documentElement;
49
+ }
50
+ return null;
51
+ }
52
+
53
+
54
+ function TestUpdates1(evt)
55
+ {
56
+ var tnode=SVGDocument.getElementById("graphtitle");
57
+ tnode.firstChild.nodeValue="Changed by Ajax2";
58
+ }
59
+
60
+ // Switch between detailed and mini legend panels
61
+ function showMiniLegend()
62
+ {
63
+ var l_hide = SVGDocument.getElementById("legendpanel_detail");
64
+ if (l_hide)
65
+ {
66
+ l_hide.setAttributeNS(null, 'visibility', 'hidden');
67
+ }
68
+ var l_show = SVGDocument.getElementById("legendpanel_mini");
69
+ if (l_show)
70
+ {
71
+ l_show.setAttributeNS(null, 'visibility', 'visible');
72
+ }
73
+ }
74
+
75
+ // Switch between detailed and mini legend panels
76
+ function showDetailedLegend()
77
+ {
78
+ var l_hide = SVGDocument.getElementById("legendpanel_mini");
79
+ if (l_hide)
80
+ {
81
+ l_hide.setAttributeNS(null, 'visibility', 'hidden');
82
+ }
83
+ var l_show = SVGDocument.getElementById("legendpanel_detail");
84
+ if (l_show)
85
+ {
86
+ l_show.setAttributeNS(null, 'visibility', 'visible');
87
+ }
88
+ }
89
+
90
+ // The chart needs to fill in the following options
91
+ // axurl , response will either do noop/full/delta replacement
92
+ function SvgAjaxUpdate()
93
+ {
94
+ var gerbilAjaxBlock=SVGDocument.getElementById("GerbilAjaxBlock");
95
+ var gerbilAjaxOptions=SVGDocument.getElementById("GerbilAjaxOptions");
96
+ var gerbilAjaxContext=SVGDocument.getElementById("GerbilAjaxContext");
97
+
98
+ // extract the URL & other ajax options from the Gerbil Ajax Block
99
+ var url = gerbilAjaxOptions.attributes.getNamedItem('axurl').nodeValue;
100
+ var freq = gerbilAjaxOptions.attributes.getNamedItem('axfrequency').nodeValue;
101
+ var decay = gerbilAjaxOptions.attributes.getNamedItem('axdecay').nodeValue;
102
+
103
+ // return the entire ajax context in request
104
+ var aa = $A(gerbilAjaxContext.attributes);
105
+ var hContext = $H();
106
+ aa.each(function (at){
107
+ hContext[at.localName]=at.nodeValue;
108
+ });
109
+ hContext.unset('_object');
110
+
111
+ // console.log ("URL = "+ url );
112
+ new Ajax.Request(url, {
113
+ method: 'post',
114
+ parameters: { 'resource': hContext['resource'] },
115
+ onSuccess: function(transport) {
116
+ updateSVG(transport.responseXML)
117
+ }
118
+ });
119
+
120
+ }
121
+ // For WebTrisul 1.0, we don't yet support delta replace,
122
+ // full replace seems to be fast enough (caching on server side)
123
+ function updateSVG(node)
124
+ {
125
+ var cmd = '';
126
+ cmd = node.documentElement.getAttribute("command")
127
+
128
+ if (cmd == "noop")
129
+ {
130
+ // do nothing (we got a noop ajax response)
131
+ }
132
+ else if (cmd=="full_replace")
133
+ {
134
+ // replace the old node with the new one
135
+ var newnode = node.documentElement.childNodes[1];
136
+ var currnode = SVGDocument.getElementById('GerbilSVGGraph');
137
+ var par = currnode.parentNode;
138
+ var newLayer = SVGDocument.importNode(newnode,true);
139
+ par.appendChild(newLayer);
140
+ par.removeChild(currnode);
141
+
142
+ // move tooltip to top of rendering stack
143
+ par.removeChild(toolTip);
144
+ par.appendChild(toolTip);
145
+ }
146
+ else if (cmd=="delta_replace")
147
+ {
148
+ // delta svg replace not yet supported
149
+ }
150
+
151
+ }
152
+
153
+ // releases any server side ajax resources held by this document
154
+ function Uninit(evt)
155
+ {
156
+ var gerbilAjaxContext=SVGDocument.getElementById("GerbilAjaxContext");
157
+ if (gerbilAjaxContext!=null)
158
+ {
159
+ var aa = $A(gerbilAjaxContext.attributes);
160
+ var hContext = $H();
161
+ aa.each(function (at){
162
+ hContext[at.localName]=at.nodeValue;
163
+ });
164
+
165
+ // console.log ("URL = "+ url );
166
+ new Ajax.Request("/axupdate/gerbilUnload", {
167
+ method: 'post',
168
+ parameters: { 'resource': hContext['resource'] },
169
+ });
170
+ }
171
+
172
+ }
173
+
174
+ function Init(evt)
175
+ {
176
+ SVGDocument = evt.target.ownerDocument;
177
+ SVGRoot = SVGDocument.documentElement;
178
+ TrueCoords = SVGRoot.createSVGPoint();
179
+
180
+ toolTip = SVGDocument.getElementById('ToolTip');
181
+ tipBox = SVGDocument.getElementById('tipbox');
182
+ tipText = SVGDocument.getElementById('tipText');
183
+ tipTitle = SVGDocument.getElementById('tipTitle');
184
+ tipDesc = SVGDocument.getElementById('tipDesc');
185
+ //window.status = (TrueCoords);
186
+
187
+ //create event for object
188
+ SVGRoot.addEventListener('mousemove', ShowTooltip, false);
189
+ SVGRoot.addEventListener('mouseout', HideTooltip, false);
190
+
191
+ // periodical executor
192
+ var gerbilAjaxOptions=SVGDocument.getElementById("GerbilAjaxOptions");
193
+ if (gerbilAjaxOptions!=null)
194
+ {
195
+ var ajaxInterval = gerbilAjaxOptions.getAttribute('axfrequency');
196
+ ajaxPE = new PeriodicalExecuter(SvgAjaxUpdate,parseInt(ajaxInterval));
197
+
198
+ // for Adobe SVG later
199
+ // setTimeout("SvgAjaxUpdate()",parseInt(ajaxInterval));
200
+ }
201
+ };
202
+
203
+
204
+ function GetTrueCoords(evt)
205
+ {
206
+ // zoom / pan adjustment
207
+ var newScale = SVGRoot.currentScale;
208
+ var translation = SVGRoot.currentTranslate;
209
+ TrueCoords.x = (evt.clientX - translation.x)/newScale;
210
+ TrueCoords.y = (evt.clientY - translation.y)/newScale;
211
+ };
212
+
213
+
214
+ function HideTooltip( evt )
215
+ {
216
+ toolTip.setAttributeNS(null, 'visibility', 'hidden');
217
+ };
218
+
219
+
220
+ function ShowTooltip( evt )
221
+ {
222
+ // bail out early, if same target
223
+ var targetElement = evt.target;
224
+ if ( lastElement == targetElement )
225
+ {
226
+ return
227
+ }
228
+
229
+ // bail out early, if no 'gerbiltooltipX' tags
230
+ // tooltip1 is the heading (appears in bold face)
231
+ // tooltip2 is the tip text
232
+ var tooltip1 = '';
233
+ var tooltip2 = '';
234
+ tooltip1 = targetElement.getAttributeNS(null, 'gerbiltooltip1');
235
+ tooltip2 = targetElement.getAttributeNS(null, 'gerbiltooltip2');
236
+ if (tooltip1=='' && tooltip2 == '')
237
+ {
238
+ return;
239
+ }
240
+
241
+ // Positon the tooltip box relative to the mouse pos
242
+ GetTrueCoords( evt );
243
+ var tipScale = 1/SVGRoot.currentScale;
244
+ var textWidth = 0;
245
+ var tspanWidth = 0;
246
+ var boxHeight = 20;
247
+ tipBox.setAttributeNS(null, 'transform', 'scale(' + tipScale + ',' + tipScale + ')' );
248
+ tipText.setAttributeNS(null, 'transform', 'scale(' + tipScale + ',' + tipScale + ')' );
249
+
250
+ // Values for tooltip text
251
+ tipTitle.firstChild.nodeValue = tooltip1;
252
+ tipTitle.setAttributeNS(null, 'display', 'inline' );
253
+ tipDesc.firstChild.nodeValue = tooltip2;
254
+ tipDesc.setAttributeNS(null, 'display', 'inline' );
255
+
256
+
257
+ // Box size
258
+ var outline = tipText.getBBox();
259
+ tipBox.setAttributeNS(null, 'width', Number(outline.width) + 10);
260
+ tipBox.setAttributeNS(null, 'height', Number(outline.height));
261
+
262
+
263
+ // Update position (keep tooltip inside client area ! )
264
+ var yPos = TrueCoords.y + (10 * tipScale);
265
+ if (yPos+Number(outline.height)>SVGRoot.height.baseVal.value)
266
+ {
267
+ yPos = SVGRoot.height.baseVal.value - Number(outline.height)
268
+ }
269
+ var xPos = TrueCoords.x + (10 * tipScale);
270
+ if (xPos+Number(outline.width)>SVGRoot.width.baseVal.value)
271
+ {
272
+ xPos = SVGRoot.width.baseVal.value - Number(outline.width)
273
+ }
274
+
275
+ toolTip.setAttributeNS(null, 'transform', 'translate(' + xPos + ',' + yPos + ')');
276
+ toolTip.setAttributeNS(null, 'visibility', 'visible');
277
+ }
278
+
279
+
280
+
281
+ //////////////////////////////////////
282
+ // Tracker - for SVG
283
+ var fTracking=0;
284
+ var nTrackBegin=0;
285
+ var nTrackEnd=0;
286
+ var nTrackCurrent=0;
287
+ var pGTrackingRect=null;
288
+ var pTrackingRect=null;
289
+ var pTrackFromTS=null;
290
+ var nTrackScale=0;
291
+ var pTrackTextFromTS=null;
292
+ var pTrackTextInterval=null;
293
+ var pTrackerData=null;
294
+
295
+ function TrackerMouseDown( evt )
296
+ {
297
+ fTracking=1;
298
+ nTrackBegin=evt.clientX;
299
+ nTrackCurrent=evt.clientX;
300
+
301
+ SVGDocument = evt.target.ownerDocument;
302
+
303
+ pGTrackingRect= SVGDocument.getElementById('gtrackerrect');
304
+ pTrackingRect= SVGDocument.getElementById('trackerrect');
305
+ pTrackingRect.setAttributeNS(null,"x",nTrackCurrent);
306
+ pTrackingRect.setAttributeNS(null,"width",1);
307
+
308
+ pTrackingText= SVGDocument.getElementById('gtrackertext');
309
+ pTrackingText.setAttributeNS(null,"transform","translate(" + nTrackBegin + ',' + 150 + ')');
310
+
311
+ // compute begin state
312
+ pTrackerData = SVGDocument.getElementById('gtrackerdata');
313
+ nTrackScale = parseInt(pTrackerData.getAttributeNS(null,"gerb_scale"));
314
+ var from_secs = parseInt(pTrackerData.getAttributeNS(null,"gerb_fromts"));
315
+
316
+ // clicked to time delta
317
+ var xbegin = parseInt(SVGDocument.getElementById('trackerpanel').getAttributeNS(null,"x"));
318
+ pTrackFromTS = new Date();
319
+ pTrackFromTS.setTime(1000* (from_secs + (nTrackBegin-xbegin)*nTrackScale));
320
+
321
+ // text svg elements
322
+ pTrackTextFromTS=SVGDocument.getElementById('trackertextfromts');
323
+ pTrackTextInterval=SVGDocument.getElementById('trackertextinterval');
324
+
325
+ // visibility off (move 5-10 pixels to turn it on)
326
+ pGTrackingRect.setAttributeNS(null,"visibility","hidden");
327
+ pTrackingText.setAttributeNS(null,"visibility","hidden");
328
+
329
+ }
330
+
331
+ function TrackerMouseMove(evt)
332
+ {
333
+ if (fTracking==2 && evt.clientX > nTrackBegin)
334
+ {
335
+ var delta = nTrackCurrent-nTrackBegin;
336
+ var mid = nTrackBegin+(delta)/2;
337
+ nTrackCurrent=evt.clientX;
338
+ pTrackingRect.setAttributeNS(null,"width",delta);
339
+ pTrackingText.setAttributeNS(null,"transform","translate(" + mid + ')');
340
+
341
+ // text box
342
+ var szwin = FormatSecs(delta*nTrackScale)
343
+ var szbegin = "Starting : " + pTrackFromTS.toLocaleString();
344
+ pTrackTextInterval.firstChild.nodeValue = szwin;
345
+ pTrackTextFromTS.firstChild.nodeValue = szbegin;
346
+ }
347
+ else if (fTracking==1 && (evt.clientX-nTrackBegin) > 5 )
348
+ {
349
+ // we need to move atleast 5 pixels to turn on tracking
350
+ fTracking=2;
351
+
352
+ // visibility on
353
+ pGTrackingRect.setAttributeNS(null,"visibility","visible");
354
+ pTrackingText.setAttributeNS(null,"visibility","visible");
355
+ }
356
+ }
357
+ function TrackerMouseUp(evt)
358
+ {
359
+ if (fTracking==2)
360
+ {
361
+ pTrackingRect=null;
362
+ nTrackEnd=evt.clientX;
363
+
364
+ pTrackerData.setAttributeNS(null,"gerb_selsecs",(nTrackEnd-nTrackBegin)*nTrackScale);
365
+ pTrackerData.setAttributeNS(null,"gerb_selts", pTrackFromTS.getTime()/1000);
366
+
367
+ }
368
+ fTracking=0;
369
+ }
370
+
371
+ function FormatSecs(secs)
372
+ {
373
+ if (secs>86400) {
374
+ return "" + Math.floor(secs/86400) + " Days" + Math.floor((secs%86400)/3600) + " Hrs" + Math.round((secs%3600)/60) + " Mins";
375
+ } else if (secs>3600) {
376
+ return "" + Math.floor(secs/3600) + " Hrs " + Math.round((secs%3600)/60) + " Mins";
377
+ } else if (secs>60) {
378
+ return "" + Math.floor(secs/60) + " Mins " + secs%60 + " Secs";
379
+ }
380
+ return "" + secs + " Secs";
381
+ }
@@ -0,0 +1,56 @@
1
+ require 'json'
2
+ require 'lita'
3
+ require 'open-uri'
4
+ require 'base64'
5
+ require 'gerbilcharts'
6
+ module Lita
7
+ module Handlers
8
+ class Gerbile < Handler
9
+ config :config.trisul.host, type: String, required: true
10
+ config :config.trisul.port, type: Integer, required: true
11
+ $id=rand(100)
12
+ extend Lita::Handler::HTTPRouter
13
+ http.get "/kkr:id.png", :example
14
+ def example(request,response)
15
+ chart_generate()
16
+ `rsvg-convert /tmp/sq_linechart.svg -o /home/lita/robot/test.png`
17
+ file=File.read("/home/lita/robot/test.png")
18
+ response2["Content-Type"] = "image/png"
19
+ response2.write(file)
20
+ response2.finish
21
+ p "/kkr#{$id}.png"
22
+ end
23
+
24
+
25
+ def chart_generate()
26
+ test_vector_tm1 = []
27
+ tbeg = Time.local( 1978, "jun", 5, 9, 10, 0, 0)
28
+ sbeg = tbeg
29
+ sec_inc = 50
30
+ for i in (0..20)
31
+ test_vector_tm1 << [sbeg + i*sec_inc, i*sec_inc*250*rand() ]
32
+ end
33
+ mod1 = GerbilCharts::Models::TimeSeriesGraphModel.new("External Gateway")
34
+ mod1.add_tuples test_vector_tm1
35
+ modgroup = GerbilCharts::Models::GraphModelGroup.new("Hosts")
36
+ modgroup.add(mod1)
37
+ mychart = GerbilCharts::Charts::LineChart.new( :width => 750, :height => 250, :squarize => true,:javascripts => ['inline:gerbil.js' ],
38
+ :auto_tooltips => false, :style => 'inline:brushmetal.css' )
39
+ mychart.setmodelgroup(modgroup)
40
+ mychart.render('/tmp/sq_linechart.svg')
41
+ end
42
+
43
+
44
+ route(/^chart me/, :charts, command: false, help: { "charts" => "To test http" })
45
+
46
+
47
+ def charts(response)
48
+ response.reply("http://139.59.66.54:9000/kkr#{$id}.png")
49
+ $id=rand(100)
50
+ end
51
+
52
+ end#CLASS
53
+ Lita.register_handler(Gerbile)
54
+ end#module handlers
55
+ end#modulelita
56
+
@@ -0,0 +1,67 @@
1
+ require 'json'
2
+ require 'lita'
3
+ require 'open-uri'
4
+ require 'base64'
5
+ module Lita
6
+ module Handlers
7
+ class Hello < Handler
8
+ $id=rand(100)
9
+ extend Lita::Handler::HTTPRouter
10
+ http.get "/kkr:id.png", :example
11
+ def example(request,response2)
12
+ `ruby /home/lita/test_lines.rb`
13
+ `rsvg-convert /tmp/sq_linechart.svg -o /home/lita/robot/test.png`
14
+ file=File.read("/home/lita/robot/test.png")
15
+ response2["Content-Type"] = "image/png"
16
+ response2.write(file)
17
+ response2.finish
18
+ p "/kkr#{$id}.png"
19
+ end
20
+
21
+ route(/^hey\s(.*)/, :index, command: false, help: { "index" => "To test trp" })
22
+ route(/^hey$/, :index, command: false, help: { "index" => "To test trp" })
23
+ route(/^image/, :imagery, command: false, help: { "imagery" => "test to send image thru http" })
24
+ route(/^pug me plis/, :hyper, command: false, help: { "hyper" => "To test http" })
25
+
26
+
27
+
28
+ def index(response)
29
+
30
+ if response.matches[0]=="hey" and ! response.matches[0].is_a?Array
31
+
32
+ response.reply("Please enter hey <counter_group_id>")
33
+ end
34
+ conn = "tcp://demo.trisul.org:12006"
35
+ tint = TRP::TimeInterval.new()
36
+ tint.to= TRP::Timestamp.new({:tv_sec=>Time.now.tv_sec})
37
+ tint.from= TRP::Timestamp.new()
38
+ tint.from.tv_sec = tint.to.tv_sec - 3600
39
+ req = TrisulRP::Protocol.mk_request(TRP::Message::Command::COUNTER_GROUP_TOPPER_REQUEST,{:counter_group=>response.matches[0][0],:meter=>0,:maxitems=>2,time_interval:tint})
40
+ TrisulRP::Protocol.get_response_zmq(conn,req) do |resp|
41
+ resp.keys.each do |key|
42
+ response.reply("#{key.label}=#{key.metric*300}")
43
+ end
44
+ end
45
+ end#def
46
+
47
+
48
+
49
+
50
+ def imagery(response)
51
+ response.reply("http://139.59.66.54:9000/kkr#{$id}.png")
52
+ $id=rand(100)
53
+
54
+ end
55
+
56
+
57
+
58
+ def hyper(response)
59
+ response.reply("ihello")
60
+ end
61
+
62
+
63
+
64
+ end#CLASS
65
+ Lita.register_handler(Hello)
66
+ end#module handlers
67
+ end#modulelita
@@ -0,0 +1,72 @@
1
+ require 'json'
2
+ require 'lita'
3
+ require 'open-uri'
4
+ require 'base64'
5
+ require 'gerbilcharts'
6
+ module Lita
7
+ module Handlers
8
+ class Gerbile < Handler
9
+ config :config.trisul.host, type: String, required: true
10
+ config :config.public.host, type: String, required: true
11
+ $id=rand(100)
12
+ extend Lita::Handler::HTTPRouter
13
+ http.get "/kkr:id.png", :example
14
+ def example(request,response)
15
+ chart_generate()
16
+ `rsvg-convert /tmp/chart.svg -o /tmp/chart.png`
17
+ file=File.read("/tmp/chart.png")
18
+ response2["Content-Type"] = "image/png"
19
+ response2.write(file)
20
+ response2.finish
21
+ end
22
+
23
+
24
+ def chart_generate(test_vector_tm1)
25
+ test_vector_tm1 = []
26
+ tbeg = Time.local( 1978, "jun", 5, 9, 10, 0, 0)
27
+ sbeg = tbeg
28
+ sec_inc = 50
29
+ for i in (0..20)
30
+ test_vector_tm1 << [sbeg + i*sec_inc, i*sec_inc*250*rand() ]
31
+ end
32
+ mod1 = GerbilCharts::Models::TimeSeriesGraphModel.new("External Gateway")
33
+ mod1.add_tuples test_vector_tm1
34
+ modgroup = GerbilCharts::Models::GraphModelGroup.new("Hosts")
35
+ modgroup.add(mod1)
36
+ mychart = GerbilCharts::Charts::LineChart.new( :width => 750, :height => 250, :squarize => true,:javascripts => ['inline:gerbil.js' ],
37
+ :auto_tooltips => false, :style => 'inline:brushmetal.css' )
38
+ mychart.setmodelgroup(modgroup)
39
+ mychart.render('/tmp/chart.svg')
40
+ end
41
+
42
+
43
+ route(/^chart me/, :trpchart, command: false, help: { "trchart" => "To chart trp" })
44
+
45
+
46
+ def trpchart(response)
47
+ if response.matches[0]=="hey" and ! response.matches[0].is_a?Array
48
+ response.reply("Please enter hey <counter_group_id>")
49
+ end
50
+ conn = "tcp://$config.trisul.host"
51
+ tint = TRP::TimeInterval.new()
52
+ tint.to= TRP::Timestamp.new({:tv_sec=>Time.now.tv_sec})
53
+ tint.from= TRP::Timestamp.new()
54
+ tint.from.tv_sec = tint.to.tv_sec - 3600
55
+ req = TrisulRP::Protocol.mk_request(TRP::Message::Command::COUNTER_GROUP_TOPPER_REQUEST,{:counter_group=>response.matches[0][0],:meter=>0,:maxitems=>2,time_interval:tint})
56
+ data = []
57
+ TrisulRP::Protocol.get_response_zmq(conn,req) do |resp|
58
+ resp.keys.each do |key|
59
+ #response.reply("#{key.label}=#{key.metric*300}")
60
+ data << [#{key.label},#{key.metric}]
61
+ end
62
+ end
63
+ chart_generate(data)
64
+ response.reply("http://$config.public.host/kkr#{$id}.png")
65
+ $id=rand(100)
66
+ end#def
67
+
68
+ end#CLASS
69
+ Lita.register_handler(Gerbile)
70
+ end#module handlers
71
+ end#modulelita
72
+
data/lib/lita-trisul.rb CHANGED
@@ -10,3 +10,6 @@ Lita::Handlers::Trisul.template_root File.expand_path(
10
10
  File.join("..", "..", "templates"),
11
11
  __FILE__
12
12
  )
13
+ require "lita/handlers/lita-hello"
14
+ require "lita/handlers/lita-gerbile"
15
+ require 'trisulrp'
data/lita-trisul.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-trisul"
3
- spec.version = "0.2.0"
3
+ spec.version = "0.2.2"
4
4
  spec.authors = ["Krishna"]
5
5
  spec.email = ["info@unleashnetworks.com"]
6
6
  spec.description = "Lita chatops to Trisul Network Analytics"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-trisul
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Krishna
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-24 00:00:00.000000000 Z
11
+ date: 2017-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
@@ -134,6 +134,11 @@ files:
134
134
  - README.md
135
135
  - Rakefile
136
136
  - lib/lita-trisul.rb
137
+ - lib/lita/handlers/brushmetal.css
138
+ - lib/lita/handlers/gerbil.js
139
+ - lib/lita/handlers/lita-gerbile.rb
140
+ - lib/lita/handlers/lita-hello.rb
141
+ - lib/lita/handlers/lita-trpgerbil.rb
137
142
  - lib/lita/handlers/trisul.rb
138
143
  - lita-trisul.gemspec
139
144
  - locales/en.yml
@@ -161,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
166
  version: '0'
162
167
  requirements: []
163
168
  rubyforge_project:
164
- rubygems_version: 2.4.5.2
169
+ rubygems_version: 2.5.1
165
170
  signing_key:
166
171
  specification_version: 4
167
172
  summary: Chatbot interface to network traffic and security monitoring