-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathislandora_microservices_monitor.module
178 lines (159 loc) · 5.07 KB
/
islandora_microservices_monitor.module
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
<?php
/*
* @file islandora_microservices_monitor.module
* defines paths (drupal menu items) as entry points and acts as a hub for dispatching tasks to other modules.
*
*
* This file is part of Islandora.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program. If not, see <http ://www.gnu.org/licenses/>.
*/
/**
* Implementation of hook_menu.
* Build menus for general view, object view and admin settings page.
*/
function islandora_microservices_monitor_menu() {
$items = array();
$items['admin/islandora/microservices_monitor'] = array(
'title' => 'Microservices configuration',
'description' => 'Configure settings for Islandora microservices.',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_microservices_monitor_admin'),
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
'weight' => -1,
);
$items['islandora_microservices_monitor'] = array(
'title' => 'Islandora microservices monitor',
'page callback' => 'islandora_microservices_monitor_view',
'type' => MENU_NORMAL_ITEM,
'access arguments' => array('administer site configuration'),
);
$items['islandora/object/%islandora_object/manage/microservices_monitor'] = array(
'title' => 'Microservices',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_microservices_monitor_object_form', 2),
'type' => MENU_LOCAL_TASK,
'access arguments' => array('administer site configuration'),
'weight' => 5,
);
return $items;
}
/**
* Build form for admin settings
*
* @return type
*/
function islandora_microservices_monitor_admin() {
$form = array();
$form['islandora_microservices_monitor_listener_ip'] = array(
'#type' => 'textfield',
'#title' => t('Listener IP address'),
'#default_value' => variable_get('islandora_microservices_monitor_listener_ip', 'localhost'),
'#size' => 12,
);
$form['islandora_microservices_monitor_listener_port'] = array(
'#type' => 'textfield',
'#title' => t('Listener port'),
'#default_value' => variable_get('islandora_microservices_monitor_listener_port', '80'),
'#size' => 8,
);
return system_settings_form($form);
}
/**
* Build general view for microservices log
*
* @return type
*/
function islandora_microservices_monitor_view() {
$form = array();
$ch = curl_init();
$address = variable_get('islandora_microservices_monitor_listener_ip', 'localhost');
$port = variable_get('islandora_microservices_monitor_listener_port', '80');
curl_setopt($ch, CURLOPT_URL, "http://$address:$port/index.php?action=list");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
$list_array = json_decode($response);
// $list_array = array_filter(explode("\n", $list));
$list_arrays = array();
if ($list_array) {
foreach ($list_array as $line) {
$list_arrays[] = explode(', ', $line);
}
$headers = array(
t('Date'),
t('Time'),
t('Level'),
t('Action'),
t('PID'),
t('DSID'),
t('User'),
t('Message'),
t('Script'),
);
$form['table'] = array(
'#theme' => 'table',
'#header' => $headers,
'#rows' => $list_arrays,
);
}
else {
drupal_set_message(t('No respsonse from the processing server!'), 'warning');
}
return $form;
}
/**
* Build form to show microservices events for individual objects
*
* @param type $form
* @param type $form_state
* @param $fedora_object $object
* @return $form
*/
function islandora_microservices_monitor_object_form($form, &$form_state, $object) {
$ch = curl_init();
$address = variable_get('islandora_microservices_monitor_listener_ip', 'localhost');
$port = variable_get('islandora_microservices_monitor_listener_port', '80');
curl_setopt($ch, CURLOPT_URL, "http://$address:$port/index.php?action=object&pid=$object->id");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
$list_array = json_decode($response);
// $list_array = array_filter(explode("\n", $list));
$list_arrays = array();
if ($list_array) {
foreach ($list_array as $line) {
$list_arrays[] = explode(', ', $line);
}
}
$headers = array(
t('Date'),
t('Time'),
t('Level'),
t('Action'),
t('PID'),
t('DSID'),
t('User'),
t('Message'),
t('Script'),
);
$form['table'] = array(
'#theme' => 'table',
'#header' => $headers,
'#rows' => $list_arrays,
'#empty' => t('No entries found for this object'),
);
return $form;
}