Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

[CLAPI] Several bugs on HG / CG when export is filtered #5297

Closed
Sims24 opened this issue Jun 1, 2017 · 2 comments
Closed

[CLAPI] Several bugs on HG / CG when export is filtered #5297

Sims24 opened this issue Jun 1, 2017 · 2 comments

Comments

@Sims24
Copy link

Sims24 commented Jun 1, 2017


BUG REPORT INFORMATION

Centreon Web version: 2.7.11

Centreon Engine version: NR

Centreon Broker version: NR

OS: EMS

Additional environment details (AWS, VirtualBox, physical, etc.): NR

Steps to reproduce the issue:

  1. target a hostgroup or a contact group to export
    eg : [root@sims-ces-misc centreon-clapi]# /usr/bin/centreon -u admin -p miaou --select 'HG;All' --filter-type 'HG' -e

Describe the results you received:
HG;ADD;ALL;ALL
HG;setparam;ALL;hg_activate;1
HG;addhost;ESX;srvi-1
HG;addhost;ESX;srvi-2
HG;addhost;ESX;srvi-3
HG;addhost;ESX;srvi-4
HG;addhost;ALL;Centreon-Server
HG;addhost;hg1;Centreon-Server
HG;addhost;Linux-Servers;Centreon-Server
HG;addhost;ALL;Centreon-PP
HG;addhost;hg1;Centreon-PP
HG;addhost;Linux-Servers;Centreon-PP
HG;addhost;TEST;srvi-1
HG;addhost;TEST;srvi-2
HG;addhost;TEST;srvi-3
HG;addhost;TEST;srvi-4

Describe the results you expected:
HG;ADD;ALL;ALL
HG;setparam;ALL;hg_activate;1
HG;addhost;ALL;Centreon-Server
HG;addhost;ALL;Centreon-PP

Additional information you think important (e.g. issue happens only occasionally):

public function export($filter_id=null, $filter_name=null) {
        $filters = null;
        if (!is_null($filter_id)) {
            $filters = array('cg_id' => $filter_id);
        }
        parent::export($filters);
        $relObj = new Centreon_Object_Relation_Contact_Group_Contact();
        $contactObj = new Centreon_Object_Contact();
        $cgFieldName = $this->object->getUniqueLabelField();
        $cFieldName = $contactObj->getUniqueLabelField();
        $elements = $relObj->getMergedParameters(
            array($cgFieldName),
            array($cFieldName, "contact_id"),
            -1,
            0,
            $cgFieldName);

        foreach ($elements as $element) {
            $this->api->export_filter('CONTACT', $element['contact_id'], $element[$cgFieldName]);
            echo $this->action . $this->delim . "addcontact" . $this->delim . $element[$cgFieldName] . $this->delim . $element[$cFieldName] . $this->delim . $element['contact_alias'] . "\n";
        }
    }

BUT above fix doesn't help regarding addcontact/addhost that are not related to my filters ..

Thanks

@Sims24
Copy link
Author

Sims24 commented Jun 1, 2017

Ok I've done a patch, as php is never the easiest option for me please confirm it's OK for you and I'll make a PR to fix this on CG and HG.

"centreonContactGroup.class.php"

public function export($filter_id=null, $filter_name=null) {
        $filters = null;
        if (!is_null($filter_id)) {
            $filters = array('cg_id' => $filter_id);
        }
        parent::export($filters);
        $relObj = new Centreon_Object_Relation_Contact_Group_Contact();
        $contactObj = new Centreon_Object_Contact();
        $cgFieldName = $this->object->getUniqueLabelField();
        $cFieldName = $contactObj->getUniqueLabelField();
        $elements = $relObj->getMergedParameters(
            array($cgFieldName),
            array($cFieldName, "contact_name"),
            -1,
            0,
            null,
            "ASC",
            array('cg_name' => $filter_name),
            "AND");

        foreach ($elements as $element) {
            $this->api->export_filter('CONTACT', $element['contact_id'], $element[$cgFieldName]);
            echo $this->action . $this->delim . "addcontact" . $this->delim . $element[$cgFieldName] . $this->delim . $element[$cFieldName] . $this->delim . $element['contact_alias'] . "\n";
        }
}

Thanks

@Sims24
Copy link
Author

Sims24 commented Jun 1, 2017

For the hostgroups :

"centreonHostGroup.class.php"

public function export($filter_id=null, $filter_name=null)
    {
        $filters = null;
        if (!is_null($filter_id)) {
            $filters = array('hg_id' => $filter_id);
        }
        parent::export($filters);
        $relObj = new Centreon_Object_Relation_Host_Group_Host();
        $hostObj = new Centreon_Object_Host();
        $hgFieldName = $this->object->getUniqueLabelField();
        $hFieldName = $hostObj->getUniqueLabelField();
        $elements = $relObj->getMergedParameters(
            array($hgFieldName),
            array($hFieldName, 'host_id'),
            -1,
            0,
            null,
            "ASC",
            array('hg_name' => $filter_name),
            "AND");
        foreach ($elements as $element) {
            $this->api->export_filter('HOST', $element['host_id'], $element[$hFieldName]);
            echo $this->action . $this->delim .
                "addhost" . $this->delim . $element[$hgFieldName] . $this->delim.$element[$hFieldName] . "\n";
        }
}

Also please advise on indentation as it's not the same in every file and I'm not aware of PHP guidelines on it.

Sims24 pushed a commit to Sims24/centreon that referenced this issue Jun 7, 2017
Sims24 pushed a commit to Sims24/centreon that referenced this issue Jun 7, 2017
@lpinsivy lpinsivy added area/api kind/bug Security status/in-backlog A dev will begin to work on your modifications soon and removed Security labels Jun 14, 2017
kduret pushed a commit that referenced this issue Jul 12, 2017
* #5297 [CLAPI] Several bugs on HG / CG when export is filtered 

Fix contact group filtered member export

* fix filters on CG export

* Update centreonHostGroup.class.php
@kduret kduret self-assigned this Jul 12, 2017
@kduret kduret added status/implemented and removed status/in-backlog A dev will begin to work on your modifications soon labels Jul 12, 2017
@kduret kduret added this to the 2.7.12 milestone Jul 12, 2017
@lpinsivy lpinsivy closed this as completed Aug 3, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants