Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Commit

Permalink
Add WS Shinken tags
Browse files Browse the repository at this point in the history
This Web service may be called by import-glpi Shinken module to get a
list of Shinken tags associated with a tag.
This WS:
1/ search for a tagged entity
2/ list this entity's immediate sons
3/ returns the list of the sons' tags (if some exist ...)
  • Loading branch information
mohierf committed Sep 3, 2015
1 parent 0b07a32 commit 1b7e237
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
4 changes: 3 additions & 1 deletion hook.php
Expand Up @@ -605,7 +605,9 @@ function plugin_monitoring_registerMethods() {

$WEBSERVICES_METHOD['monitoring.shinkenGetConffiles'] = array('PluginMonitoringWebservice',
'methodShinkenGetConffiles');
# Get commands for arbiter
# Web services for Shinken arbiter
$WEBSERVICES_METHOD['monitoring.shinkenTags'] = array('PluginMonitoringWebservice',
'methodShinkenTags');
$WEBSERVICES_METHOD['monitoring.shinkenCommands'] = array('PluginMonitoringWebservice',
'methodShinkenCommands');
$WEBSERVICES_METHOD['monitoring.shinkenHosts'] = array('PluginMonitoringWebservice',
Expand Down
56 changes: 56 additions & 0 deletions inc/webservice.class.php
Expand Up @@ -128,6 +128,62 @@ static function methodShinkenGetConffiles($params, $protocol) {



static function methodShinkenTags($params, $protocol) {
if (!isset($params['tag'])) {
return array();
}

$tag = $params['tag'];
PluginMonitoringToolbox::logIfExtradebug(
'pm-shinken',
" - shinkenTags, get tags for: $tag\n"
);

$a_tags = array();

// Get list of entities tagged with the tag ...
$pmEntity = new PluginMonitoringEntity();
$Entity = new Entity();
$a_entities_allowed = $pmEntity->getEntitiesByTag($tag);
if (! isset($a_entities_allowed['-1'])) {
$a_entities_list = array();
foreach ($a_entities_allowed as $idEntity) {
PluginMonitoringToolbox::logIfExtradebug(
'pm-shinken',
" - shinkenTags, found entity: $idEntity\n"
);

foreach ($Entity->find("entities_id='$idEntity'") as $son) {
PluginMonitoringToolbox::logIfExtradebug(
'pm-shinken',
" - shinkenTags, found son entity: {$son['id']}\n"
);
$a_entities_list[] = $son['id'];
}
}
foreach ($a_entities_list as $idEntity) {
PluginMonitoringToolbox::logIfExtradebug(
'pm-shinken',
" - shinkenTags, search tags for entity: $idEntity\n"
);

$tag = $pmEntity->getTagByEntities($idEntity);
if (! empty($tag)) {
$a_tags[] = $tag;
}
}
}

PluginMonitoringToolbox::logIfExtradebug(
'pm-shinken',
" - shinkenTags, tags: ".serialize($a_tags)."\n"
);

return $a_tags;
}



static function methodShinkenCommands($params, $protocol) {

$pmShinken = new PluginMonitoringShinken();
Expand Down

0 comments on commit 1b7e237

Please sign in to comment.