-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathREADME.html
520 lines (426 loc) · 12.7 KB
/
README.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>README</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<meta name="title" content="README"/>
<meta name="generator" content="Org-mode"/>
<meta name="generated" content="2013-05-28T10:25-0700"/>
<meta name="author" content="Jaime Fournier"/>
<meta name="description" content=""/>
<meta name="keywords" content=""/>
<style type="text/css">
<!--/*--><![CDATA[/*><!--*/
html { font-family: Times, serif; font-size: 12pt; }
.title { text-align: center; }
.todo { color: red; }
.done { color: green; }
.tag { background-color: #add8e6; font-weight:normal }
.target { }
.timestamp { color: #bebebe; }
.timestamp-kwd { color: #5f9ea0; }
.right {margin-left:auto; margin-right:0px; text-align:right;}
.left {margin-left:0px; margin-right:auto; text-align:left;}
.center {margin-left:auto; margin-right:auto; text-align:center;}
p.verse { margin-left: 3% }
pre {
border: 1pt solid #AEBDCC;
background-color: #F3F5F7;
padding: 5pt;
font-family: courier, monospace;
font-size: 90%;
overflow:auto;
}
table { border-collapse: collapse; }
td, th { vertical-align: top; }
th.right { text-align:center; }
th.left { text-align:center; }
th.center { text-align:center; }
td.right { text-align:right; }
td.left { text-align:left; }
td.center { text-align:center; }
dt { font-weight: bold; }
div.figure { padding: 0.5em; }
div.figure p { text-align: center; }
div.inlinetask {
padding:10px;
border:2px solid gray;
margin:10px;
background: #ffffcc;
}
textarea { overflow-x: auto; }
.linenr { font-size:smaller }
.code-highlighted {background-color:#ffff00;}
.org-info-js_info-navigation { border-style:none; }
#org-info-js_console-label { font-size:10px; font-weight:bold;
white-space:nowrap; }
.org-info-js_search-highlight {background-color:#ffff00; color:#000000;
font-weight:bold; }
/*]]>*/-->
</style>
<script type="text/javascript">
/*
@licstart The following is the entire license notice for the
JavaScript code in this tag.
Copyright (C) 2012-2013 Free Software Foundation, Inc.
The JavaScript code in this tag is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
@licend The above is the entire license notice
for the JavaScript code in this tag.
*/
<!--/*--><![CDATA[/*><!--*/
function CodeHighlightOn(elem, id)
{
var target = document.getElementById(id);
if(null != target) {
elem.cacheClassElem = elem.className;
elem.cacheClassTarget = target.className;
target.className = "code-highlighted";
elem.className = "code-highlighted";
}
}
function CodeHighlightOff(elem, id)
{
var target = document.getElementById(id);
if(elem.cacheClassElem)
elem.className = elem.cacheClassElem;
if(elem.cacheClassTarget)
target.className = elem.cacheClassTarget;
}
/*]]>*///-->
</script>
</head>
<body>
<div id="preamble">
</div>
<div id="content">
<h1 class="title">README</h1>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#sec-1">1 pinky - Monitoring system built on Openresty</a>
<ul>
<li><a href="#sec-1-1">1.1 Purpose:</a></li>
<li><a href="#sec-1-2">1.2 How to build plugins:</a>
<ul>
<li><a href="#sec-1-2-1">1.2.1 Pinky rest structure</a></li>
<li><a href="#sec-1-2-2">1.2.2 Nginx configuration</a></li>
<li><a href="#sec-1-2-3">1.2.3 Pinky functions</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<div id="outline-container-1" class="outline-2">
<h2 id="sec-1"><span class="section-number-2">1</span> pinky - Monitoring system built on Openresty</h2>
<div class="outline-text-2" id="text-1">
</div>
<div id="outline-container-1-1" class="outline-3">
<h3 id="sec-1-1"><span class="section-number-3">1.1</span> Purpose:</h3>
<div class="outline-text-3" id="text-1-1">
</div>
</div>
<div id="outline-container-1-2" class="outline-3">
<h3 id="sec-1-2"><span class="section-number-3">1.2</span> How to build plugins:</h3>
<div class="outline-text-3" id="text-1-2">
</div>
<div id="outline-container-1-2-1" class="outline-4">
<h4 id="sec-1-2-1"><span class="section-number-4">1.2.1</span> Pinky rest structure</h4>
<div class="outline-text-4" id="text-1-2-1">
<ul>
<li id="sec-1-2-1-1">/pinky/ -<br/>
All modules are loaded from here.
There is no requirement for nginx.conf additions as a catchall
for pinky.dispatch() is handled via /pinky/*
<ul>
<li id="sec-1-2-1-1-1">Every custom module require a preamble containing the following.<br/>
<pre class="example">local p = require 'pinky'
local json = require 'cjson'
</pre>
<p>
This covers pulling in pinky core as well as json for output
formatting.
</p>
<p>
Additionally you are required to create an entry function
called main that takes the truncated uri as it's sole argument.
</p>
<pre class="example">local empty;
local foo;
local bar;
</pre>
<p>
Here we provide declarations of each function as local.
</p>
<pre class="example">local function pinky_main(uri)
-- This function is the entry point.
-- We are passed the rest of the uri.
local args = p.split(uri,"/")
if #args == 0 then
return json.encode("Hello controller called with no args! (e.g. http://localhost/pinky/hello)"
elseif #args == 1 then
return json.encode("Hello controller called with one arg, foo! (e.g. http://localhost/pinky/hello/foo)"
elseif #args == 2 then
return json.encode("Hello controller called with two arg, foo! (e.g. http://localhost/pinky/hello/foo)"
end
end
</pre>
<p>
We strip out all previous portions of the url including the
controller name (e.g. "/hello/")
</p>
<p>
Each plugin is can enforces its own rest argument format.
In this example we have three levels.
</p>
<p>
Based on each we call a different function with the arguments
provided.
</p>
<pre class="example">function empty()
return "Hello controller called with no args! (e.g. http://localhost/pinky/hello)"
end
function foo()
return "Hello controller called with one arg, foo! (e.g. http://localhost/pinky/hello/foo)"
end
function bar()
return "Hello controller called with two args, foo and bar! (e.g. http://localhost/pinky/hello/foo/bar)"
end
</pre>
<p>
Finally we export which functions are publicly available.
</p>
<pre class="example">return { pinky_main = pinky_main }
</pre>
<p>
For almost all cases only pinky_main should be exported.
Unless there is a need to make the functions available inside
other plugins.
</p>
</li>
</ul>
</li>
</ul>
</div>
</div>
<div id="outline-container-1-2-2" class="outline-4">
<h4 id="sec-1-2-2"><span class="section-number-4">1.2.2</span> Nginx configuration</h4>
<div class="outline-text-4" id="text-1-2-2">
<p> You will need to include the following in your nginx.conf
</p>
<pre class="example">server {
listen 44444;
location ~ /pinky/* {
content_by_lua '
local pinky = require("pinky")
ngx.say(pinky.dispatch(ngx.var.uri))
';
}
}
</pre>
</div>
</div>
<div id="outline-container-1-2-3" class="outline-4">
<h4 id="sec-1-2-3"><span class="section-number-4">1.2.3</span> Pinky functions</h4>
<div class="outline-text-4" id="text-1-2-3">
<ul>
<li id="sec-1-2-3-1">Library<br/>
<ul>
<li id="sec-1-2-3-1-1">exec_command(command,fields,key_field,sep,tokenize)<br/>
This function handles executing external commands.
<p>
The arguments are:
</p><ul>
<li>command: A String containing the full path to the binary and its arguments.
</li>
<li>Fields: A table of the numeric positions to return.
</li>
<li>Key_field: The position to use as the hash key.
</li>
<li>Sep: Regular expression to split each line of output from
command.
</li>
<li>Tokenize: Boolean to return output as a table, or a string.
<ul>
<li>true = return table
</li>
<li>nil = return string
</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul>
<li id="sec-1-2-3-1-2">dispatch(uri)<br/>
Handler for all /pinky/ functions.
<p>
Any calls to /pinky/foo will result in
foo.lua being loaded if it exists.
Then foo.pinky_main() will be called with the uri relative to /pinky/
</p>
</li>
</ul>
<ul>
<li id="sec-1-2-3-1-3">file_exists(filename)<br/>
Function to verify a fully qualified path/file exists.
Returns boolean.
</li>
</ul>
<ul>
<li id="sec-1-2-3-1-4">lsdir (path)<br/>
Function to return the files in the directory passed as an argument.
</li>
</ul>
<ul>
<li id="sec-1-2-3-1-5">print_table(in_table)<br/>
Iterate over a table and
</li>
</ul>
<ul>
<li id="sec-1-2-3-1-6">return_fields(in_table,fields)<br/>
</li>
</ul>
<ul>
<li id="sec-1-2-3-1-7">show_functions(module)<br/>
</li>
</ul>
<ul>
<li id="sec-1-2-3-1-8">split(pString, pPattern)<br/>
Split a string into a table with pattern.
</li>
</ul>
<ul>
<li id="sec-1-2-3-1-9">dispatch(uri)<br/>
Handler for all /pinky/ functions.
<p>
Any calls to /pinky/foo will result in
foo.lua being loaded if it exists.
Then foo.pinky_main() will be called with the uri relative to /pinky/
</p>
</li>
</ul>
<ul>
<li id="sec-1-2-3-1-10">exec_command(command,fields,key_field,sep,tokenize)<br/>
This function handles executing external commands.
<p>
The arguments are:
</p><ul>
<li>command: A String containing the full path to the binary and its arguments.
</li>
<li>Fields: A table of the numeric positions to return.
</li>
<li>Key_field: The position to use as the hash key.
</li>
<li>Sep: Regular expression to split each line of output from
command.
</li>
<li>Tokenize: Boolean to return output as a table, or a string.
<ul>
<li>true = return table
</li>
<li>nil = return string
</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul>
<li id="sec-1-2-3-1-11">file_exists(filename)<br/>
Function to verify a fully qualified path/file exists.
Returns boolean.
</li>
</ul>
<ul>
<li id="sec-1-2-3-1-12">find_first_file(array_of_files)<br/>
This function takes a list of files and returns the first one
that exists. Given platform differences we may have several
places we look for something like rvm. With this we return the
first one found.
</li>
</ul>
<ul>
<li id="sec-1-2-3-1-13">get_home<br/>
return the home directory of the current user pinky is running
as.
</li>
</ul>
<ul>
<li id="sec-1-2-3-1-14">get_ip(hostname)<br/>
resolve the hostname provided to us.
We use this to avoid using user input directly in commands.
</li>
</ul>
<ul>
<li id="sec-1-2-3-1-15">get_os<br/>
Return operating system name as seen by uname.
</li>
</ul>
<ul>
<li id="sec-1-2-3-1-16">get_username<br/>
Return full username of the current pinky process.
</li>
</ul>
<ul>
<li id="sec-1-2-3-1-17">lsdir(directory)<br/>
Return a table of all of the files/directories listed within.
</li>
</ul>
<ul>
<li id="sec-1-2-3-1-18">return_fields<br/>
Used in exec_command to return only those columns requested.
</li>
</ul>
<ul>
<li id="sec-1-2-3-1-19">split(string,delimiter)<br/>
Lua lacks a natural string#split command so this provides it.
</li>
</ul>
<ul>
<li id="sec-1-2-3-1-20">treewalker(path,function)<br/>
This function will walk a directory tree returning all files it
finds. This is used in items like /proc where we want the full
ps tree.
</li>
</ul>
<ul>
<li id="sec-1-2-3-1-21">trim(string)<br/>
Remove trailing white space.
</li>
</ul>
<ul>
<li id="sec-1-2-3-1-22">print_table(table)<br/>
Debug method used when resolving problems.
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div id="postamble">
<p class="date">Date: 2013-05-28T10:25-0700</p>
<p class="author">Author: Jaime Fournier</p>
<p class="creator"><a href="http://orgmode.org">Org</a> version 7.9.3f with <a href="http://www.gnu.org/software/emacs/">Emacs</a> version 24</p>
<a href="http://validator.w3.org/check?uri=referer">Validate XHTML 1.0</a>
</div>
</body>
</html>