Powershell scripts (Installed programs and running/not running services)

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply
enrikio
Posts: 14
Joined: Wed Jan 10, 2024 8:32 am

Powershell scripts (Installed programs and running/not running services)

Post by enrikio »

Hello,

I am pretty new to Cacti and have recently deployed it to Ubuntu Server with some Windows Server devices that successfully show graphs of disks, cpu...now I want a little more out of it besides default "templates".

Is there any way to implement powershell scripts into cacti server that would monitor and get data about installed programs and running/not running services that should be running on Windows Servers 2016+.

Upon looking into this I found out that you should place scripts in following folder on ubuntu cacti server:
/var/www/html/cacti/scripts

Example powershell script for installed programs i would like to use (I dropped it into /var/www/html/cacti/scripts/GetInstalledPrograms.ps1):

# PowerShell script to get a list of installed programs on Windows
# Get the list of installed programs
$installedPrograms = Get-WmiObject -Class Win32_Product | Select-Object Name, Version, Vendor
# Output the results in a format suitable for Cacti
foreach ($program in $installedPrograms) {
Write-Output "$program.Name,$program.Version,$program.Vendor"
}


Then i created new Data Input Method With type "Script/command" and input string "/var/www/html/cacti/scripts/GetInstalledPrograms.ps1".
In output fields I Added name ProgramInfo.

Then I created device template WindowsProgramsInfo, that points to internal data source name "ProgramInfo", that I created previosly.

Is this the right approach so far and what steps should i make next so I can see this data next to my graphs in device tree.

Many thanks!
jab50
Posts: 13
Joined: Wed Aug 26, 2015 3:46 am

Re: Powershell scripts (Installed programs and running/not running services)

Post by jab50 »

From my attempts its not so simple.
The powershell cmdlet get-wmiobject only works on the local instance - So you need to pipe out through Invoke-Command to the remote server. Unfortunately the Ubuntu implementation of PS dosent support Invoke-command. So I used some Python code to connect to the remote WinRM interface.
See viewtopic.php?t=62823 for some work I used to go down this route. It works to collect basic information so should work for anything else if you put sufficient scripting in place.

It might be simpler to start with cacti on a windows server or at least a remote poller on windows but ive not tried that route yet.

Post back if you get anywhere.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests