Skip to main content

Hello everybody,

I am new to this wiki and to centreon in general.

My task is to set up alerts on our windows server in evaluation version (180 days) when they approach the invalidity date (at 3 days for example)

I tried several scripts but without success, here are the steps I followed with the help of different tutorials here and there : 

- create the folder usr/lib/centreon/plugins/custom on the poller1 under CentOS in which I created the script Alert_windows_license.py

# -*- coding: utf-8 -*-

import os
import subprocess
import re
import datetime

# Récupère les variables d'environnement pour l'identifiant et le mot de passe Windows - Retrieves the environment variables for the Windows login and password
windows_username = os.environr'WINDOWS_USERNAME']
windows_password = os.environr'WINDOWS_PASSWORD']

# Adresse IP du serveur Windows - IP address of the Windows server
server_ip = "$ARG1$"

# Exécute la commande PowerShell avec l'identifiant et le mot de passe de l'utilisateur Windows - Executes the PowerShell command with the Windows user ID and password
powershell_cmd = "powershell.exe -Command \"& {Get-WmiObject -Class SoftwareLicensingProduct -ComputerName " + server_ip + " -Credential (New-Object System.Management.Automation.PSCredential('" + windows_username + "', (ConvertTo-SecureString '" + windows_password + "' -AsPlainText -Force))) | Where-Object {$_.Description -eq 'Windows(R) Operating System, VOLUME_KMSCLIENT channel'} | Select-Object Description, LicenseStatus, LicenseExpirationDate}\""

# Exécute la commande PowerShell et stocke la sortie dans une variable - Executes the PowerShell command and stores the output in a variable
output = subprocess.check_output(powershell_cmd, shell=True)

# Analyse la sortie de la commande pour extraire la date d'expiration de la licence - Analyzes the output of the command to extract the expiration date of the license
license_date_regex = re.compile(r"LicenseExpirationDate\s+:\s+(\d{4})(\d{2})(\d{2})\s+(\d{2}):(\d{2}):(\d{2})")
license_date_match = license_date_regex.search(output.decode('utf-8'))

if license_date_match:
# Calcule le nombre de jours restants jusqu'à la date d'expiration de la licence
license_year = int(license_date_match.group(1))
license_month = int(license_date_match.group(2))
license_day = int(license_date_match.group(3))
license_hour = int(license_date_match.group(4))
license_minute = int(license_date_match.group(5))
license_second = int(license_date_match.group(6))

license_expiration_date = datetime.datetime(license_year, license_month, license_day, license_hour, license_minute, license_second)
days_until_expiration = (license_expiration_date - datetime.datetime.now()).days

if days_until_expiration <= 3:
print("La licence Windows Server 2019 Standard Evaluation expire dans moins de 3 jours !")
else:
print("La licence Windows Server 2019 Standard Evaluation expire dans {} jours.".format(days_until_expiration))
else:
print("Impossible de trouver la date d'expiration de la licence.")

 

- In centreon web I created the command "Alert_windows-license" with Command Line "/usr/lib/centreon/plugins/custom/Alert_windows_license.py $ARG1$", Argument Example : " $ARG1$ "

- So I attached it to my windows server and here is the Status information : (No output returned from plugin)

 

If you have any idea on how to resolve the issue, or simply another idea on how to achieve my task i’ll be happy to hear it ! 

Thanks

Hi @aja please try to execute your plugin witch ‘centreon-engine’ user:

su - centreon-engine
/usr/lib/centreon/plugins/custom/Alert_windows_license.py

Moreover, you script try to execute powershell.exe, so this will not work from a Linux server.

If you need to execute this script directly on the Windows server, you will need an Agent such as Nsclient++


Reply