Use Centreon API easily from Powershell
- Enable Reach API Configuration and/or Reach API Realtime on the user. (Centreon Permissions)
Install the module from the PowerShell Gallery.
Install-Module CentreonPS
Get-Command -Module CentreonPS
Functions | Descriptions |
---|---|
New-CentreonConnection | To connect to the Centreon Server |
Get-CentreonHostStatus | Return the centreon hosts status in realtime |
Get-CentreonServiceStatus | Return the centreon services status in realtime |
Invoke-CentreonCommand | To manage the centreon objects (add,delete,set,show...) |
You have to re-do this step when the token has expired.
$Session = New-CentreonConnection -server "192.168.1.50"
$Credentials = Get-Credential -UserName fclisson
$Session = New-CentreonConnection -server "192.168.0.30" -Credentials $Credentials
Invoke-CentreonCommand allow to manage any centreon object.
You have to specify the object
that you want to manage then which action
you want to do on it and lastly the value values
expected.
Action and object list available from : Centreon Clapi documentation.
The following command line allow to add an Host to Centreon :
Invoke-CentreonCommand -Session $Session -object HOST -action ADD -Values "test;Test host;127.0.0.1;OS-Linux-SNMP-custom;central;Centreon_platform"
The following command line, allow to show the contact groups :
Invoke-CentreonCommand -Session $Session -object CG -action show
Get-CentreonServiceStatus -Session $Session
host_id : 15
name : Centeon-central
description : Broker-Retention
service_id : 95
state : 0
state_type : 1
output : OK: centreon-broker failover/temporary files are ok
Checking config '/etc/centreon-broker/central-rrd.xml'\nskipping temporary: no configuration set\nChecking config
'/etc/centreon-broker/central-broker.xml'\nskipping temporary: no configuration set\n
perfdata :
max_check_attempts : 3
check_attempt : 1
last_check : 1531062538
last_state_change : 1528587027
last_hard_state_change : 1528587027
acknowledged : 0
criticality :
Get-CentreonHostsStatus -Session $Session
Get-CentreonHostsStatus -Session $Session -status all -order ASC -search '%rsys%'
id : 15
name : Centeon-central
alias : Centreon central server
address : 127.0.0.1
state : 0
state_type : 1
output : OK - 127.0.0.1: rta 0.025ms, lost 0%
max_check_attempts : 3
check_attempt : 1
last_check : 1531060693
last_state_change : 1528586735
last_hard_state_change : 1528586735
acknowledged : 0
instance_name : Central
criticality :
- Not sure that the powershell plugin works with https,to try?
- Manage case when the token is expired
- Include authentification from default credentials (Active Directory Auth)
- Create Set-CentreonServerConfig?
- Create dynamic parameters on the Invoke-CentreonCommand function