prod_check_xmlrpc.module in Production check & Production monitor 8
Production check XML-RPC connector
File
modules/prod_check_xmlrpc/prod_check_xmlrpc.moduleView source
<?php
/**
* @file
* Production check XML-RPC connector
*/
use Drupal\prod_check\Entity\ProdCheckProcessor;
/**
* Implements hook_xmlrpc
*/
function prod_check_xmlrpc_xmlrpc() {
return [
[
'prod_check.get_settings',
'prod_check_xmlrpc_get_settings',
[
'struct',
'string',
],
t("Returns a struct containing a form to be displayed on the prod_monitor module's settings page for site specific configuration."),
],
[
'prod_check.get_data',
'prod_check_xmlrpc_get_data',
[
'struct',
'string',
'struct',
],
t('Returns a struct containing the result of all requested checks.'),
],
];
}
/**
* Returns a keyed array of functions that can be parsed by the receiver into
* a form or status page.
*/
function prod_check_xmlrpc_get_settings($ping_key) {
$data = FALSE;
/** @var ProdCheckProcessor $xmlrpc_processor */
$xmlrpc_processor = ProdCheckProcessor::load('xmlrpc');
if ($xmlrpc_processor && $xmlrpc_processor
->getPlugin()
->verifyKey($ping_key)) {
$data = $xmlrpc_processor
->getPlugin()
->listPlugins();
}
return $data;
}
/**
* XMLRPC callback function that returns all data of requested checks.
*
* @param ping_key
* Api key for this site
* @param checks
* Array of all checks to perform
*
* @return
* Array of all data to be displayed by the requesting site in a 'status_form' theme.
*/
function prod_check_xmlrpc_get_data($ping_key, $checks) {
$data = FALSE;
$checkmanager = \Drupal::service('plugin.manager.prod_check');
$definitions = $checkmanager
->getDefinitions();
/** @var ProdCheckProcessor $xmlrpc_processor */
$xmlrpc_processor = ProdCheckProcessor::load('xmlrpc');
if ($xmlrpc_processor && $xmlrpc_processor
->getPlugin()
->verifyKey($ping_key)) {
$data = [];
foreach ($checks as $set => $calls) {
$data[$set] = [];
foreach ($calls as $plugin_id) {
if (isset($definitions[$plugin_id])) {
$plugin = $checkmanager
->createInstance($plugin_id, $definitions[$plugin_id]);
$check = $xmlrpc_processor
->getPlugin()
->process($plugin);
if (is_array($check) && !empty($check)) {
$data[$set][$plugin_id] = $check;
}
}
}
}
}
return $data;
}
Functions
Name | Description |
---|---|
prod_check_xmlrpc_get_data | XMLRPC callback function that returns all data of requested checks. |
prod_check_xmlrpc_get_settings | Returns a keyed array of functions that can be parsed by the receiver into a form or status page. |
prod_check_xmlrpc_xmlrpc | Implements hook_xmlrpc |