PowerShell script exchange
Post Reply
Silviu
Novice
Posts: 3
Liked: 2 times
Joined: Mar 19, 2019 1:04 pm
Full Name: SV
Contact:

License Expiration Centreon

Post by Silviu » Nov 07, 2019 11:04 am

Hello Veeam Community,

I would like to monitor with Centreon the support expiration date. I've found some PS scripts :

https://exchange.nagios.org/index.php?o ... word=veeam

But these scripts only show the B&R license's expiration :

Image

and I would like to see the support expiration date in my console :

Image

Here is the part of powershell's code that "extract" the date :

Code: Select all

# We obtain the license information consulting it's registry key.
# Getting registry key information.
$regkey_veeam = (Get-Item 'HKLM:\SOFTWARE\VeeaM\Veeam Backup and Replication\license').GetValue('Lic1')
# Converting registry key into human readable content.
$lic_veeam = [string]::Join($null, ($regkey_veeam | ForEach-Object { [char][int]$_;}))

# Extracting the expiration date using the previously defined $pattern_date.
$expdate_veeam = [regex]::matches($lic_veeam,$pattern_date)[0].Value.Split("=")[1]
# Getting the days until today.
$licdays_veeam = [int](((Get-Date $expdate_veeam) - (Get-Date)).TotalDays.toString().split(",")[0])
Is there something I can change in this code to get the date I want ?

Regards,

oleg.feoktistov
Veeam Software
Posts: 33
Liked: 12 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: License Expiration Centreon

Post by oleg.feoktistov » Nov 07, 2019 12:15 pm 4 people like this post

Hi,

To parse support expiration date you would actually need to modify the other part of the code you shared: the search pattern.

Should be:

Code: Select all

$pattern_date = "Support expiration date\=\d{1,2}\/\d{1,2}\/\d{1,4}"
instead of:

Code: Select all

$pattern_date = "Expiration date\=\d{1,2}\/\d{1,2}\/\d{1,4}"
Then, amend the output statements accordingly and that should suffice.

Kind regards,
Oleg

Silviu
Novice
Posts: 3
Liked: 2 times
Joined: Mar 19, 2019 1:04 pm
Full Name: SV
Contact:

Re: License Expiration Centreon

Post by Silviu » Nov 08, 2019 9:00 am 2 people like this post

Hello Oleg,

Was so simple in fact. Than you very much, it worked like a charm :

Image

Have a nice day !

arun.kr
Service Provider
Posts: 17
Liked: never
Joined: Aug 16, 2014 1:13 am
Full Name: Arun Kumar
Contact:

Re: License Expiration Centreon

Post by arun.kr » Nov 11, 2019 7:52 am

Hello Oleg,

As per VEEAM console my license will expire in 118 days but when I executed below code output is 264 days. On my VEEAM server short and long date formats are M/d/yyyy and dddd, MMMM d, yyyy respectively.

Image

Code: Select all

$veeamExe = Get-Item 'C:\Program Files\Veeam\Backup and Replication\Backup\Veeam.Backup.Manager.exe'
$regBinary = (Get-Item 'HKLM:\SOFTWARE\VeeaM\Veeam Backup and Replication\license').GetValue('Lic1')
$veeamLicInfo = [string]::Join($null, ($regBinary | % { [char][int]$_; }))

if($veeamExe.VersionInfo.ProductVersion -match "9"){
    $pattern = "Expiration date\=\d{1,2}\/\d{1,2}\/\d{1,4}"
}
else{
    $pattern = "EXPIRATION DATE\=\d{1,2}\/\d{1,2}\/\d{1,4}"
}

$expirationDate = [regex]::matches($VeeamLicInfo, $pattern)[0].Value.Split("=")[1]
$totalDaysLeft = ((Get-Date $expirationDate) - (get-date)).Totaldays.toString().split(",")[0]
$totalDaysLeft = [int]$totalDaysLeft

Code: Select all

PS C:\Users\> $totalDaysLeft = ((Get-Date $expirationDate) - (get-date)).Totaldays.toString().split(",")[0]

PS C:\Users\akumar> $totalDaysLeft
263.88284124677

PS C:\Users\akumar> $totalDaysLeft = [int]$totalDaysLeft

PS C:\Users\akumar> $totalDaysLeft
264
How could I tweak the code to read appropriate date format.

oleg.feoktistov
Veeam Software
Posts: 33
Liked: 12 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: License Expiration Centreon

Post by oleg.feoktistov » Nov 11, 2019 2:01 pm 1 person likes this post

Hi Arun,

It should have nothing to do with date formats distinctions since on the step below both date values are being presented in the same format right before subtraction:

Code: Select all

$totalDaysLeft = ((Get-Date $expirationDate) - (get-date)).Totaldays.toString().split(",")[0]
When you run the code on your Veeam Backup server, what are the outputs of get-date and $veeamLicInfo respectively?

Thank you,

arun.kr
Service Provider
Posts: 17
Liked: never
Joined: Aug 16, 2014 1:13 am
Full Name: Arun Kumar
Contact:

Re: License Expiration Centreon

Post by arun.kr » Nov 13, 2019 6:02 am

Hello Oleg,

here is the output.

Output of get-date
Wednesday, November 13, 2019 12:56:23 AM

Output of $veeamLicInfo
Expiration date=08/01/2020
Support expiration date=08/03/2020

oleg.feoktistov
Veeam Software
Posts: 33
Liked: 12 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: License Expiration Centreon

Post by oleg.feoktistov » Nov 15, 2019 10:10 am

Hi Arun,

So, the code parses the info correctly. That's odd VBR console shows different information.
Just wondering if your VBR console is connecting to the same server you execute the code on.

Oleg

arun.kr
Service Provider
Posts: 17
Liked: never
Joined: Aug 16, 2014 1:13 am
Full Name: Arun Kumar
Contact:

Re: License Expiration Centreon

Post by arun.kr » Nov 16, 2019 4:25 am

Yes Oleg, I am executing the code on the VEEAM server and it is connected to localhost.
I will try to execute the code on another VEEAM server and will update.

Post Reply

Who is online

Users browsing this forum: Egor Yakovlev and 3 guests