-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipeviz.drush.inc
78 lines (69 loc) · 2.05 KB
/
pipeviz.drush.inc
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
<?php
use Drupal\Core\Database\Database;
function pipeviz_drush_command() {
return array(
'pipeviz-report' => array(
'description' => 'Reports the state of the Drupal instance to a pipeviz server',
'aliases' => array('pvr'),
'arguments' => array(
'target' => 'The address of the pipeviz server to which the report should be sent.'
),
'bootstrap' => DRUSH_BOOTSTRAP_MAX,
'required-arguments' => TRUE,
'options' => array(
'db' => 'Report the database configuration.'
),
)
);
}
// TODO D7 compatibility
function drush_pipeviz_report($target) {
$message = array();
if (drush_get_option('db')) {
$all = Database::getAllConnectionInfo();
$ls = array();
$environment = array(
'address' => array(
'hostname' => gethostname(),
),
);
foreach ($all as $outer => $sets) {
foreach ($sets as $name => $info) {
$conn = array(
'hostname' => $info['host'],
'proto' => 'tcp',
);
// Add the 3306 by default for mysql.
// TODO such defaults are clearly handled elsewhere in Drupal's systems; take advantage of them instead of reimplementing here
if (empty($info['port']) && $info['driver'] == 'mysql') {
$conn['port'] = 3306;
}
$ls[] = array(
'path' => DRUPAL_ROOT,
'environment' => $environment,
'datasets' => array(
array(
'name' => $outer,
'type' => 'mediated',
'connNet' => $conn,
'interaction' => 'rw',
'subset' => $info['database'],
),
),
);
}
}
$message['logic-states'] = $ls;
} else {
drush_set_error(dt("No options were passed to pipeviz-report for reporting; no message will be sent."));
return;
}
try {
$client = new GuzzleHttp\Client();
$client->request('POST', $target, [
'body' => json_encode($message),
]);
} catch (GuzzleHttp\Exception\ClientException $e) {
echo $e->getResponse();
}
}