I need to monitor multiple licenses on several Hosts (like firewall appliances, antivirus servers, etc.). How can I do that with PRTG?


Article Comments

To monitor the licenses that are used in your network, regardless of the appliance or software, please create an EXE/Script Advanced sensor which uses the PowerShell script given below.

Set up Monitoring of license status

  • Open a text editor.
  • Copy the following code and paste it into the editor:
Param([string]$ExpirationDate)

$DateDifference = New-TimeSpan -Start (Get-Date) -End $ExpirationDate
$Days = $DateDifference.Days
$DaysPassed = ($Days * -1)
if($Days -gt 0){
                Write-Host "$($Days):License expires in $($Days) day(s)."
                exit 0 }
if($Days -eq 0){
                Write-Host "$($Days):The license expires today!";
                exit 1
}
if($Days -lt 0){
                Write-Host "0:License expired for $($DaysPassed) days!"
                exit 1
}
  • Save the file and name it, e.g., license_status.ps1
  • Place the script in the \Custom Sensors\EXE sub-directory of your PRTG installation to ensure that the EXE/Script Advanced sensor can pick up the same.
  • Create a new EXE/Script Sensor .
    • Choose license_status.ps1 as executable.
    • As Parameter, pass the following: ExpirationDate="2015-31-12"
    • Please note that the date format must suit your system default (i.e. DD.MM.YYYY for german)

The sensor will show you the remaining days of your license. It also shows how many days the license is already expired if that is the case. Please don't forget to set lower limits in the channel settings to get notified a few days earlier.

Best regards.


May, 2014 - Permalink

Hi,

This script doesn't work anymore (error code PE231). Do you have one that works with version 18.3.42?

Thanks & regards


Jul, 2018 - Permalink

It should work properly. How are you passing the parameters?


Kind regards,
Stephan Linke, Tech Support Team


Jul, 2018 - Permalink

Has somebody already test it with PRTG 18x ? If it doesn't work, has somebody an update ?

Regards

Frederic


Jul, 2018 - Permalink

It should work properly. How are you passing the parameters?


Jul, 2018 - Permalink

@prtg_eurogentec

I copied the above code in an ps1 file: expdate.ps1 then execute it in powershell with .\expdate.ps1 "01-12-2018" this works for me. (datetime is german, you may need to enter 'expdate.ps1 2018-12-01' for your country"

ergards Thomas


Jul, 2018 - Permalink

Thomas is correct here, make sure the date notation matches the region of the PRTG server (i.e. the Windows setting). Otherwise, it'll probably error. Regardless of PRTG's version :) Thanks for chiming in, Thomas!


Kind regards,
Stephan Linke, Tech Support Team


Jul, 2018 - Permalink

Getting this error: New-TimeSpan : Cannot bind parameter 'End'. Cannot convert value "" to type "System.DateTime"

Any idea on how to fix this?


Mar, 2019 - Permalink

What's your server region and what does the end date look like?


PRTGapi | Feature Requests | WMI Issues | SNMP Issues

Kind regards,
Stephan Linke, Tech Support Team


Mar, 2019 - Permalink

United States

DD/MM/YYYY


Mar, 2019 - Permalink

Try MM/DD/YYYY instead :) That should work with that region.


PRTGapi | Feature Requests | WMI Issues | SNMP Issues

Kind regards,
Stephan Linke, Tech Support Team


Mar, 2019 - Permalink

I have created this sensor but the result it returns is not correct, the sensor is in warning state with the message 'License expired for days!' and the value is showing as 0. I have ran the powershell manually and that works fine, returning the correct number of days. The parameter I am passing is in the correct date format (the same as when I run the powershell manually on the probe). Any ideas as to why this might be happening?

Thanks

Andy


Mar, 2019 - Permalink

Seems that the answer to my question is to set the parameter in PRTG to just the date i.e. "16-12-2019" rather than ExpirationDate="16-12-2019"


Mar, 2019 - Permalink

@aojari thanks for the update, glad it's working now. The proper syntax would be the following
-ExpirationDate '16-12-2019'


Mar, 2019 - Permalink

Just adding my two cents here since I ran into this problem.

Creating the ps file I wasn't able to load it, it wouldn't show up in the EXE/Script list when creating a new sensor. Even restarting the core and probe services didn't help. I finally figured out the issue:

This would be useful to you guys who have multiple probes. Since I added the file to the custom sensor folder on the primary server, I can only view it when adding sensors to the local probe. I'm guessing I need to add it to the folder on the probe I would be using the sensor on.


Jan, 2022 - Permalink

Hi ToyRazee,

you are right. If you want to use a custom script on a Remote Probe you need to store the script there. The Remote Probe will only send the results of the sensor scans to the Core Server. This means that all sensors scans are executed by the Probe itself.


Kind regards

Felix Wiesneth - Team Tech Support


Jan, 2022 - Permalink

This script is working perfectly, thanks for sharing this folks!

The one thing I would like to change as a preference is to set the alert from "warning" when a certain threshold is met to "DOWN"

I seem to be unable to change that category on this sensor. Any advice on that leg?

Thank you, -Travis R.


Oct, 2022 - Permalink

Hi Travis,

If you change the exit code, you can change the state of the sensor. This means that you will need to adjust the script at following point:

...
                exit 1
...

I would recommend to take a look in our manual about the different exit codes here. In addition you will find the codes below:

exit codestatus
0OK
1WARNING
2System Error
3Protocol Error
4Content Error

Kind regards

Felix Wiesneth - Team Technical Support


Oct, 2022 - Permalink

To try to help, in case someone has the same problem as me. I used the script above in PRTG version 22.3.79.2108+ with various combinations of parameters, but it always returned an error.

I did some research on the internet and in a similar case, I saw that inside the script, the "Write-Host" syntax should be changed to "write-output".

And when creating the sensor, in "parameters", only the date should be placed exactly like this: "28/04/2024".

In my case, the PRTG and server are in Brazilian Portuguese, so the date is dd/MM/aaaa.


Jan, 2023 - Permalink

@razevedo it would help if you could share the error message you get. Are you able to select the script file from the UI?


Jan, 2023 - Permalink

Dear @Toy Razee,

In my case it's working perfectly. I just made the post above to help other people, if they have the same problem as me, because I spent a lot of time trying to solve it.

The error that was appearing before was the same one that has already been posted here by other people: "error code PE231".

Regards.


Jan, 2023 - Permalink

Hi @razevedo noted and thanks for pointing it out. Am sure this thread will help others trying to customize their PRTG installations. The only issue I ran into with scripts is realizing that they need to be specifically loaded to the probe used for the sensors, just loading them onto the core is not enough.


Jan, 2023 - Permalink

Hi,

Thank you for all the inputs.
You are right, you will need to store your custom scripts in C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors on the corresponding Probe, since the sensors (and also custom scripts) will be executed on the Probe and only the results will be forwarded to the Core Server.


Kind regards

Felix Wiesneth - Team Technical Support


Jan, 2023 - Permalink