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

Poc add update field nagios server #8099

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cron/centAcl-Func.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function getFilteredPollers($host, $resId)
}
}
} else {
# If result of query is empty and user have poller restriction, clean host table.
// If result of query is empty and user have poller restrictions, clean host table.
if ($isPollerFilter) {
$host = array();
}
Expand Down
87 changes: 52 additions & 35 deletions cron/centAcl.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
$centreonDbName = $conf_centreon['db'];
$centreonLog = new CentreonLog();

/*
* Define the period between two update in second for LDAP user/contactgroup
*/
define('LDAP_UPDATE_PERIOD', 3600);

/**
* CentAcl script
Expand Down Expand Up @@ -78,10 +82,7 @@
if (empty($data)) {
try {
// at first run (eg: after the install), data may be missing.
$pearDB->query(
"INSERT INTO cron_operation (name, system, activate)
VALUES ('centAcl.php', '1', '1')"
);
$pearDB->query("INSERT INTO cron_operation (name, system, activate) VALUES ('centAcl.php', '1', '1')");
} catch (\PDOException $e) {
programExit("Error can't insert centAcl values in the `cron_operation` table.");
}
Expand Down Expand Up @@ -110,9 +111,31 @@
programExit($errorMessage);
}

$resourceCache = array();
/**
* Sync ACL with LDAP's contactgroup
* If the LDAP is enabled and the last check is greater than the update period
*
* @TODO : Synchronize LDAP with contacts data in background to avoid it at login
*/
$ldapEnable = '0';
$ldapLastUpdate = 0;
$queryOptions = "SELECT `key`, `value` FROM `options` WHERE `key` IN ('ldap_auth_enable', 'ldap_last_acl_update')";
$res = $pearDB->query($queryOptions);
while ($row = $res->fetch()) {
switch ($row['key']) {
case 'ldap_auth_enable':
$ldapEnable = $row['value'];
break;
case 'ldap_last_acl_update':
$ldapLastUpdate = $row['value'];
break;
}
}
if ($ldapEnable === '1' && $ldapLastUpdate < (time() - LDAP_UPDATE_PERIOD)) {
$cgObj->syncWithLdap();
}

/** **********************************************
/**
* Check expected contact data sync on login with the LDAP, depending on last sync time and own sync interval
*/
$pearDB->beginTransaction();
Expand Down Expand Up @@ -143,14 +166,11 @@
programExit("Error when updating LDAP's reference date for next synchronization");
}

// @TODO : Synchronize LDAP with contacts data in background to avoid it at login
$cgObj->syncWithLdap();

/** **********************************************
/**
* Remove data from old groups (deleted groups)
*/
$aclGroupToDelete = "SELECT DISTINCT acl_group_id " .
"FROM " . $centreonDbName . ".acl_groups WHERE acl_group_activate = '1'";
$aclGroupToDelete = "SELECT DISTINCT acl_group_id
FROM " . $centreonDbName . ".acl_groups WHERE acl_group_activate = '1'";
$aclGroupToDelete2 = "SELECT DISTINCT acl_group_id FROM " . $centreonDbName . ".acl_res_group_relations";
$pearDB->beginTransaction();
try {
Expand All @@ -165,7 +185,7 @@
);
}

/** ***********************************************
/**
* Check if some ACL have global options selected for
* all the resources
*/
Expand All @@ -181,7 +201,6 @@
/**
* Add Hosts
*/

if ($row['all_hosts']) {
$pearDB->beginTransaction();
try {
Expand Down Expand Up @@ -219,7 +238,6 @@
}
}


/**
* Add Hostgroups
*/
Expand Down Expand Up @@ -316,7 +334,6 @@
* if no : go away.
* if yes : let's go to build cache and update database
*/

$tabGroups = array();
$dbResult1 = $pearDB->query(
"SELECT DISTINCT acl_groups.acl_group_id
Expand All @@ -333,9 +350,8 @@

if (count($tabGroups)) {

/** ***********************************************
/**
* Cache for hosts and host Templates
*
*/
$hostTemplateCache = [];
$res = $pearDB->query(
Expand All @@ -357,7 +373,7 @@
}
unset($h);

/** ***********************************************
/**
* Cache for host poller relation
*/
$hostPollerCache = array();
Expand All @@ -371,7 +387,7 @@
$hostPollerCache[$row['nagios_server_id']][$row['host_host_id']] = $row['host_host_id'];
}

/** ***********************************************
/**
* Get all included Hosts
*/
$hostIncCache = [];
Expand All @@ -386,7 +402,7 @@
$hostIncCache[$h["acl_res_id"]][$h["host_host_id"]] = 1;
}

/** ***********************************************
/**
* Get all excluded Hosts
*/
$hostExclCache = [];
Expand All @@ -401,7 +417,7 @@
$hostExclCache[$h["acl_res_id"]][$h["host_host_id"]] = 1;
}

/** ***********************************************
/**
* Service Cache
*/
$svcCache = [];
Expand All @@ -413,7 +429,7 @@
$svcCache[$s["service_id"]] = 1;
}

/** ***********************************************
/**
* Host Host relation
*/
$hostHGRelation = [];
Expand All @@ -426,7 +442,7 @@
}
unset($hg);

/** ***********************************************
/**
* Host Service relation
*/
$hsRelation = [];
Expand All @@ -453,7 +469,7 @@
}
$dbResult->closeCursor();

/** ***********************************************
/**
* Create Service template model Cache
*/
$svcTplCache = [];
Expand Down Expand Up @@ -522,17 +538,18 @@
// Prepare statement
$deleteHandler = $pearDBO->prepare("DELETE FROM centreon_acl WHERE group_id = ?");

/** ***********************************************
/**
* Begin to build ACL
*/
$cpt = 0;
$resourceCache = array();
foreach ($tabGroups as $aclGroupId) {
/*
* Delete old data for this group
*/
$deleteHandler->execute(array($aclGroupId));

/** ***********************************************
/**
* Select
*/
$dbResult2 = $pearDB->prepare(
Expand Down Expand Up @@ -733,17 +750,17 @@
$stmt->bindValue(':aclGroupId', $aclGroupId, \PDO::PARAM_INT);
$stmt->execute();
}
}

/**
* Include module specific ACL evaluation
*/
$extensionsPaths = getModulesExtensionsPaths($pearDB);
foreach ($extensionsPaths as $extensionPath) {
require_once $extensionPath . 'centAcl.php';
/**
* Include module specific ACL evaluation
*/
$extensionsPaths = getModulesExtensionsPaths($pearDB);
foreach ($extensionsPaths as $extensionPath) {
require_once $extensionPath . 'centAcl.php';
}
}

/*
/**
* Remove lock
*/
$dbResult = $pearDB->prepare(
Expand Down
10 changes: 5 additions & 5 deletions doc/en/api/clapi/objects/service_templates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,18 @@ Getmacro
In order to view the custom macro list of a service template, use the **GETMACRO** action::

[root@centreon ~]# ./centreon -u admin -p centreon -o STPL -a getmacro -v "MyTemplate"
macro name;macro value;description
$_SERVICETIME$;80;description of macro1
$_SERVICEPL$;400;description of macro2

macro name;macro value;description;is_password
$_SERVICETIME$;80;description of macro1;0
$_SERVICEPL$;400;description of macro2;0

Setmacro
--------

In order to set a macro for a specific service template use the **SETMACRO** action::

[root@centreon ~]# ./centreon -u admin -p centreon -o STPL -a setmacro -v "MyTemplate;time;80"
[root@centreon ~]# ./centreon -u admin -p centreon -o STPL -a setmacro -v "MyTemplate;pl;400"
[root@centreon ~]# ./centreon -u admin -p centreon -o STPL -a setmacro -v "MyTemplate;pl;400;description"
[root@centreon ~]# ./centreon -u admin -p centreon -o STPL -a setmacro -v "MyTemplate;password;mypassword;;1"

.. note::
You need to generate your configuration file and restart monitoring engine in order to apply changes.
Expand Down
77 changes: 57 additions & 20 deletions doc/en/faq/performance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,16 @@ Centreon storage database schema can be view here :
RRDCacheD
*********

RRDCacheD is a process to reduce disk I/O during the update of performance's graphs and status' graphs.
The RRDCacheD process is loaded by the Centreon Broker module and mutualise I/O disques instead of recording
one by one the data from the collect.
RRDCacheD is a process to reduce disk I/O during the update of performance's graphs and status' graphs. The RRDCacheD
process is loaded by the Centreon Broker module and mutualise I/O disques instead of recording one by one the data from
the collect.

Installation
============

The RRDCacheD process is available in **rrdtool** package and already installed on your server.
Execute the following command: ::

# yum install rrdtool-cached

Configuration
=============
Expand All @@ -98,14 +100,13 @@ Edit the **/etc/sysconfig/rrdcached** file and complete information::

# Settings for rrdcached
OPTIONS="-m 664 -l unix:/var/rrdtool/rrdcached/rrdcached.sock -s rrdcached -b /var/rrdtool/rrdcached -w 3600 -z 3600 -f 7200"
RRDC_USER=rrdcach
RRDC_USER=rrdcached

.. note::
The order of setting is pretty important. If **-m 664** is define before **-l unix:/var/rrdtool/rrdcached/rrdcached.sock** option then rights will be incorrect on socket.

Options are following one:


+--------+-----------------------------------------------------------------------------------+
| Option | Description |
+========+===================================================================================+
Expand All @@ -118,44 +119,80 @@ Options are following one:
+--------+-----------------------------------------------------------------------------------+

.. note::
Please modify values with you needs.
Please modify values with your needs.

Creating the service startup file
*********************************

Replace the default **/usr/lib/systemd/system/rrdcached.service** init script: ::

# cp /usr/share/centreon/examples/rrdcached.systemd /usr/lib/systemd/system/rrdcached.service

Execute following commands: ::

mkdir -p /var/rrdtool
useradd rrdcached -d '/var/rrdtool/rrdcached' -G centreon-broker,centreon -m
chmod 775 -R /var/rrdtool

Groups configuration
********************

Create groups using commands::
Create groups using commands: ::

# usermod -a -g rrdcached centreon-broker
# usermod -a -g rrdcached apache
# usermod -a -g centreon rrdcached
# usermod -a -g centreon-broker rrdcached
# usermod -a -G rrdcached centreon-broker
# usermod -a -G rrdcached apache
# usermod -a -G centreon rrdcached
# usermod -a -G centreon-broker rrdcached

Restart Apache process::
Restart process: ::

# systemctl restart httpd24-httpd
# systemctl daemon-reload
# systemctl enable rrdcached
# systemctl start rrdcached

Start RRDCacheD process::
Check the status of the process: ::

# /etc/init.d/rrdcached start
# systemctl status rrdcached
● rrdcached.service - Data caching daemon for rrdtool
Loaded: loaded (/etc/systemd/system/rrdcached.service; disabled; vendor preset: disabled)
Active: active (running) since ven. 2018-10-26 10:14:08 UTC; 39min ago
Docs: man:rrdcached(1)
Main PID: 28811 (rrdcached)
CGroup: /system.slice/rrdcached.service
└─28811 /usr/bin/rrdcached -m 664 -l unix:/var/rrdtool/rrdcached/rrdcached.sock -s rrdcached -b /var/rrdtool/rrdcached -w 7200 -f 14400 -z 3600 -p /var/rrdtool/rrdcached/rrdcached.pid

oct. 26 10:14:08 demo-front rrdcached[28811]: starting up
oct. 26 10:14:08 demo-front systemd[1]: Started Data caching daemon for rrdtool.
oct. 26 10:14:08 demo-front rrdcached[28811]: listening for connections
oct. 26 10:14:08 demo-front systemd[1]: Starting Data caching daemon for rrdtool...

Centreon web configuration
**************************

Go to **Administration > Options > RRDTool** menu, enable process and set unix socket path:
Go to **Configuration > Pollers > Broker configuration** menu, select the broker inserting data into RRD files then in
the **Output** tab enable process and set unix socket path:

* Enable RRDCached: unix
* RRDCacheD listening socket/port: /var/rrdtool/rrdcached/rrdcached.sock

Enable process and set unix socket path:

.. image:: /images/faq/rrdcached_config.png
:align: center

.. warning::
Instead of configuration was made into **Administration** you need to generate and export configuration of central server and restart cbd process to apply changes.
Instead of configuration was made into **Administration** you need to generate and export configuration of central
server and restart cbd process to apply changes.

.. image:: /images/faq/rrd_file_generator.png
:align: center

Centreon web interface
**********************

RRDCacheD don't update performances graphs in real time. If a blank range appears on right of performances graphs it means that cache are not yet written to disk.
RRDCacheD don't update performances graphs in real time. If a blank range appears on right of performances graphs it
means that cache are not yet written to disk.

.. warning::
If the **RRDCacheD process crash** (in theory because it's a stable process) data will be lost! It is not possible to get data unless rebuild all graphs from Centreon web.
If the **RRDCacheD process crash** (in theory because it's a stable process) data will be lost! It is not possible
to get data unless rebuild all graphs from Centreon web.
Binary file modified doc/en/images/faq/rrdcached_config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading