forked from mozilla/mig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.rst.html
283 lines (248 loc) · 13.2 KB
/
data.rst.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
<!DOCTYPE html><html><head><meta charset="utf-8"><title></title><style type="text/css">body {
width: 95%;
max-width: 70%;
margin: 20px;
padding: 0;
background: #151515 url("../images/bkg.png") 0 0;
color: #eaeaea;
font: 16px;
line-height: 1.5em;
font-family: Monaco, "Bitstream Vera Sans Mono", "Lucida Console", Terminal, monospace;
}
#table-of-contents ul {
line-height: 1;
}
/* General & 'Reset' Stuff */
.container {
width: 95%;
max-width: 1000px;
margin: 0 auto;
}
section {
display: block;
margin: 0 0 20px 0;
}
h1, h2, h3, h4, h5, h6 {
/*margin: 0 0 20px;*/
/*margin: 0;*/
}
/* Header, <header>
* header - container
* h1 - project name
* h2 - project description
* */
header {
background: rgba(0, 0, 0, 0.1);
width: 100%;
/*border-bottom: 1px dashed #b5e853;*/
/*padding: 20px 0;
* margin: 0 0 40px 0;*/
padding: 5px 0;
margin: 0 0 10px 0;
}
header h1 {
font-size: 30px;
line-height: 1.5;
margin: 0 0 0 -40px;
font-weight: bold;
font-family: Monaco, "Bitstream Vera Sans Mono", "Lucida Console", Terminal, monospace;
/*color: #b5e853;*/
color: #089d00;
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1),
0 0 5px rgba(181, 232, 83, 0.1),
0 0 10px rgba(181, 232, 83, 0.1);
letter-spacing: -1px;
-webkit-font-smoothing: antialiased;
}
header h1:before {
content: "./ ";
font-size: 24px;
}
header h2 {
font-size: 18px;
font-weight: 300;
}
/* Main Content
* */
body {
width: 100%;
margin-left: auto;
margin-right: auto;
-webkit-font-smoothing: antialiased;
}
section img {
max-width: 100%
}
h2 a {
font-weight: bold;
color: #8AB638;
line-height: 1.4em;
font-size: 1.4em;
}
h3 a, h4 a, h5 a, h6 a {
font-weight: bold;
color: #934500;
line-height: 1.4em;
}
h1 {
font-size: 30px;
}
h2 {
font-size: 28px;
border-bottom: 1px dashed #b5e853;
}
h3 {
font-size: 18px;
}
h4 {
font-size: 14px;
}
h5 {
font-size: 12px;
text-transform: uppercase;
margin: 0 0 5px 0;
}
h6 {
font-size: 12px;
text-transform: uppercase;
color: #999;
margin: 0 0 5px 0;
}
dt {
font-style: italic;
font-weight: bold;
}
/*
ul li {
list-style: none;
}
*/
/*
ul li:before {
content: ">>";
font-family: Monaco, "Bitstream Vera Sans Mono", "Lucida Console", Terminal, monospace;
font-size: 13px;
color: #b5e853;
margin-left: -37px;
margin-right: 21px;
line-height: 16px;
}
*/
blockquote {
color: #aaa;
padding-left: 10px;
border-left: 1px dotted #666;
}
pre {
background: rgba(0, 0, 0, 0.9);
border: 1px solid rgba(255, 255, 255, 0.15);
padding: 10px;
font-size: 14px;
//color: #b5e853;
border-radius: 2px;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
text-wrap: normal;
overflow: auto;
overflow-y: hidden;
}
pre.address {
margin-bottom: 0 ;
margin-top: 0 ;
font: inherit }
pre.literal-block, pre.doctest-block, pre.math, pre.code {
margin-left: 2em ;
margin-right: 2em }
code .ln { color: grey; } /* line numbers */
/*code, code { background-color: #eeeeee }*/
code .comment, code .comment, code .c1 { color: #999; }
code .keyword, code .keyword, code .kd, code .kn, code .k, code .o { color: #FC8F3F; font-weight: bold;}
code .nb { color: #c45918;}
code .s {color: #0a77c4;}
code .punctuation, code .p { color: white;}
code .literal.string, code .literal.string { color: #40BF32; }
code .name, code .name.builtin, code .nx { color: white; }
code .deleted, code .deleted { background-color: #DEB0A1}
code .inserted, code .inserted { background-color: #A3D289}
table {
width: 100%;
margin: 0 0 20px 0;
}
th {
text-align: left;
border-bottom: 1px dashed #b5e853;
padding: 5px 10px;
}
td {
padding: 5px 10px;
}
hr {
height: 0;
border: 0;
border-bottom: 1px dashed #b5e853;
color: #b5e853;
}
/* Links
* a, a:hover, a:visited
* */
a {
color: #63c0f5;
/*text-shadow: 0 0 5px rgba(104, 182, 255, 0.5);*/
text-decoration: none;
}
cite {
color: #00FF4A;
}
strong {
color: #C64216;
}
</style></head><body><h1>MIG Data</h1><div class="contents" id="table-of-contents"><h2>Table of Contents</h2><ul class="auto-toc"><li><p><a class="reference internal" href="#postgresql" id="id1">1 Postgresql</a></p><ul class="auto-toc"><li><p><a class="reference internal" href="#database-creation-script" id="id2">1.1 Database creation script</a></p></li><li><p><a class="reference internal" href="#structure-tables" id="id3">1.2 Structure & Tables</a></p></li></ul></li><li><p><a class="reference internal" href="#queries" id="id4">2 Queries</a></p><ul class="auto-toc"><li><p><a class="reference internal" href="#adding-investigators" id="id5">2.1 Adding Investigators</a></p></li><li><p><a class="reference internal" href="#finding-offline-agents" id="id6">2.2 Finding offline agents</a></p></li><li><p><a class="reference internal" href="#finding-double-agents" id="id7">2.3 Finding double agents</a></p></li></ul></li><li><p><a class="reference internal" href="#scheduler-spool" id="id8">3 Scheduler Spool</a></p></li></ul></div><section id="postgresql"><header><h2><a href="#id1">1 Postgresql</a></h2></header><section id="database-creation-script"><header><h3><a href="#id2">1.1 Database creation script</a></h3></header><p>Two scripts can be used to create a database for MIG.</p><ul><li><p><a class="reference external" href="https://github.com/mozilla/mig/blob/master/src/mig/database/createlocaldb.sh">createlocaldb.sh</a> will create a database on an instance of postgresql
running locally. This is used by the standalone installation script.</p></li></ul><ul><li><p><a class="reference external" href="https://github.com/mozilla/mig/blob/master/src/mig/database/createremotedb.sh">createremotedb.sh</a> will connect to an existing MIG database on a remote
postgresql server. This is a standard production setup. It assumes that you
have created a database beforehand. You can pass the DB credentials by
editing the bash variables at the top of the script before running it.</p></li></ul></section><section id="structure-tables"><header><h3><a href="#id3">1.2 Structure & Tables</a></h3></header><p>The full database schema is available as a SQL file in
<a class="reference external" href="https://github.com/mozilla/mig/blob/master/src/mig/database/schema.sql">src/mig/database/schema.sql</a>.</p><p>The <cite>actions</cite> table contains the detail of each action ran by the MIG platform.
Its structure contains the base action fields found in the json format of an
action, plus a number of additional fields such as timestamps and counters.</p><p>The <cite>agents</cite> table contains the registrations of each agents known of the MIG
platform.</p><p>The <cite>commands</cite> table contains each action sent to each agent.</p><p><cite>investigators</cite> have a table that contains their public PGP key, and can be
used when verifying signatures and generating ACLs.</p><p>The <cite>signatures</cite> table is a junction between an action and the investigators
that signed the action.</p></section></section><section id="queries"><header><h2><a href="#id4">2 Queries</a></h2></header><p>MIG queries are stored separately from the rest of the source code. You can
inspect and modify all queries directly in the Go files in <a class="reference external" href="https://github.com/mozilla/mig/tree/master/src/mig/database">src/mig/database</a>.</p><section id="adding-investigators"><header><h3><a href="#id5">2.1 Adding Investigators</a></h3></header><p>In the future, this will probably be automated via the API. But for now, and
until we have a strong authentication mechanism for API calls, it must be done
manually in the database.</p><p>Adapt the query below to add a new investigator.</p><pre><code class="code sql"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> <span class="name">investigators</span> <span class="punctuation">(</span><span class="name">name</span><span class="punctuation">,</span> <span class="name">pgpfingerprint</span><span class="punctuation">)</span>
<span class="keyword">VALUES</span> <span class="punctuation">(</span><span class="literal string single">'Bob Kelso'</span><span class="punctuation">,</span> <span class="literal string single">'E608......'</span><span class="punctuation">);</span></code></pre></section><section id="finding-offline-agents"><header><h3><a href="#id6">2.2 Finding offline agents</a></h3></header><p>The following query retrieves a list of agents that have been online over the
last 30 days, but have not sent a heartbeat in the last 5 minutes.</p><pre><code class="code sql"><span class="keyword">SELECT</span> <span class="keyword">DISTINCT</span><span class="punctuation">(</span><span class="name">name</span><span class="punctuation">)</span> <span class="keyword">FROM</span> <span class="name">agents</span>
<span class="keyword">WHERE</span> <span class="name">name</span> <span class="keyword">IN</span> <span class="punctuation">(</span>
<span class="keyword">SELECT</span> <span class="keyword">DISTINCT</span><span class="punctuation">(</span><span class="name">name</span><span class="punctuation">)</span> <span class="keyword">FROM</span> <span class="name">agents</span>
<span class="keyword">WHERE</span> <span class="name">heartbeattime</span> <span class="operator">>=</span> <span class="name">NOW</span><span class="punctuation">()</span> <span class="operator">-</span> <span class="name builtin">interval</span> <span class="literal string single">'30 days'</span>
<span class="punctuation">)</span> <span class="keyword">AND</span> <span class="name">name</span> <span class="keyword">NOT</span> <span class="keyword">IN</span> <span class="punctuation">(</span>
<span class="keyword">SELECT</span> <span class="keyword">DISTINCT</span><span class="punctuation">(</span><span class="name">name</span><span class="punctuation">)</span> <span class="keyword">FROM</span> <span class="name">agents</span>
<span class="keyword">WHERE</span> <span class="name">heartbeattime</span> <span class="operator">>=</span> <span class="name">NOW</span><span class="punctuation">()</span> <span class="operator">-</span> <span class="name builtin">interval</span> <span class="literal string single">'5 minutes'</span>
<span class="punctuation">)</span> <span class="keyword">ORDER</span> <span class="keyword">BY</span> <span class="name">name</span><span class="punctuation">;</span></code></pre></section><section id="finding-double-agents"><header><h3><a href="#id7">2.3 Finding double agents</a></h3></header><p>Sometimes during upgrades the older agent isn't shut down. You can find these
endpoints with double agents in the database because each agent sends separate
heartbeats for the same endpoint:</p><pre><code class="code sql"><span class="keyword">SELECT</span> <span class="keyword">COUNT</span><span class="punctuation">(</span><span class="name">queueloc</span><span class="punctuation">),</span> <span class="name">queueloc</span> <span class="keyword">FROM</span> <span class="name">agents</span>
<span class="keyword">WHERE</span> <span class="name">heartbeattime</span> <span class="operator">>=</span> <span class="name">NOW</span><span class="punctuation">()</span> <span class="operator">-</span> <span class="name builtin">INTERVAL</span> <span class="literal string single">'10 minutes'</span>
<span class="keyword">GROUP</span> <span class="keyword">BY</span> <span class="name">queueloc</span> <span class="keyword">HAVING</span> <span class="keyword">COUNT</span><span class="punctuation">(</span><span class="name">queueloc</span><span class="punctuation">)</span> <span class="operator">></span> <span class="literal number integer">1</span>
<span class="keyword">ORDER</span> <span class="keyword">BY</span> <span class="keyword">count</span><span class="punctuation">(</span><span class="name">queueloc</span><span class="punctuation">)</span> <span class="keyword">DESC</span><span class="punctuation">;</span></code></pre><p>This query will list all the agents sorted by the count of agents heartbeatting
on each endpoint:</p><pre>| count | name
|--------+--------------------------------------
| 3 | puppet3.private.dc1.example.net
| 2 | mv1.mv.example.net
| 2 | memcache1.webapp.dc1.example.net
| 2 | ip2.dc.example.net
|</pre></section></section><section id="scheduler-spool"><header><h2><a href="#id8">3 Scheduler Spool</a></h2></header><p>MIG data is stored both on the file system of the scheduler, and in the database.
On the scheduler, each action and command are stored individually in a text file
in /var/cache/mig (by default).</p><pre><code class="code bash"> <span class="name variable">$ </span>tree -d /var/cache/mig/
/var/cache/mig/
├── action
│ ├── <span class="keyword">done</span>
│ ├── inflight
│ ├── invalid
│ └── new
└── <span class="name builtin">command</span>
├── <span class="keyword">done</span>
├── inflight
├── ready
└── returned
<span class="literal number">10</span> directories
<span class="literal number">2</span> <span class="punctuation">|</span> command.private.corp.dc1.example.net</code></pre></section></body></html>