Monitoring and reporting for Veeam Backup & Replication, VMware vSphere and Microsoft Hyper-V
Shestakov
Expert
Posts: 7328
Liked: 773 times
Joined: May 21, 2014 11:03 am
Full Name: Nikita Shestakov
Location: Prague
Contact:

Re: Powershell script to forward alarms

Post by Shestakov »

You are right, we've added 7th variable with the unique alarm ID. It should work for scripts.
Could you specify how you tried to get the value?

sandsturm
Expert
Posts: 161
Liked: 13 times
Joined: Mar 23, 2015 8:30 am
Contact:

Re: Powershell script to forward alarms

Post by sandsturm »

Sorry, I had a fault in my script. I'm now able to pass this ID to a script. But now I see that the ID is always the same for the same alert, doesn't matter if the alert was thrown from different sources. I'll explain that with an example. I use the alert "Backup Job disabled" for my tests, because I can force this alert easily (I sat the "Time in disabled state to 3 Minutes"). The script just outputs the parameter values into a file. The script looks as following:

Code: Select all

set Alarm=%1
set Node=%2
set Summary=%3
set time=%4
set status=%5
set oldstatus=%6
set id=%7

echo Alarmname: %Alarm% >> C:\admin\scripts\ONEalarm.log
echo Node: %Node% >> C:\admin\scripts\ONEalarm.log
echo Summary: %Summary% >> C:\admin\scripts\ONEalarm.log
echo Date: %time% >> C:\admin\scripts\ONEalarm.log
echo Status: %status% >> C:\admin\scripts\ONEalarm.log
echo OldStatus: %oldstatus% >> C:\admin\scripts\ONEalarm.log
echo ID: %id% >> C:\admin\scripts\ONEalarm.log
echo -------------- >>C:\admin\scripts\ONEalarm.log
The output looks as following:

Alarmname: "Backup job disabled"
Node: "<VeeamServername>"
Summary: "Job '<Job_1>' is in the disabled state for more than defined in the threshold (3 minutes). "
Date: "03.04.2019 08:16:04"
Status: "Warning"
OldStatus: "Reset/resolved"
ID: "1061"
--------------
Alarmname: "Backup job disabled"
Node: "<VeeamServername>"
Summary: "Job '<Job_2>' is in the disabled state for more than defined in the threshold (3 minutes). "
Date: "03.04.2019 08:34:16"
Status: "Warning"
OldStatus: "Reset/resolved"
ID: "1061"
--------------
Alarmname: "Backup job disabled"
Node: "<VeeamServername>"
Summary: "<Job_2> are back to normal "
Date: "03.04.2019 08:35:01"
Status: "Reset/resolved"
OldStatus: "Warning"
ID: "1061"
--------------


It looks, that the ID is relevant for the Alarm ifself, but not unique for an alarm which is sent from a specific source (Job_1 or Job_2)... but that doesn't help me, because if I get the Reset/resolved alarm, I want to map this Reset/Resolved to the correct Alarm from before, that I know which alarms are solved and which are not. Do you understand my idea?

thx,
sandsturm

Shestakov
Expert
Posts: 7328
Liked: 773 times
Joined: May 21, 2014 11:03 am
Full Name: Nikita Shestakov
Location: Prague
Contact:

Re: Powershell script to forward alarms

Post by Shestakov »

I understand the idea, but "Backup job disabled" may be not the best alarm to check the behavior as object is "Backup Server", not "backup job".
Try to check the behavior with "Backup repository free space" alarm by changing the threshold(will work if you have more than 1 repository).
Thanks!

sandsturm
Expert
Posts: 161
Liked: 13 times
Joined: Mar 23, 2015 8:30 am
Contact:

Re: Powershell script to forward alarms

Post by sandsturm »

Looks better now, I have now a unique ID per repository/alert combination. So far so good....

Another question:
Is it possible to pass the alerts to a powershell script instead of a cmd or bat file?
I tried it, but if I use a powershell, then every space is used as a delimiter, for example:
I tried to use the command:

Code: Select all

powershell.exe "C:\admin\scripts\Veeam_alarm.ps1" %1 %2 %3 %4 %5 %6 %7
If the alarmname is "Backup repository free space", I have the first word "Backup" in %1, the second word "repository" in %2 and so on, if I do this with a cmd or bat, i have the complete string in %1.
I tried to use:

Code: Select all

powershell.exe "C:\admin\scripts\Veeam_alarm.ps1" -alertname %1 -node %2 ... 
but that did not work either. Is there a way to use a powershell script to process the alerts?

thx,
sandsturm

Shestakov
Expert
Posts: 7328
Liked: 773 times
Joined: May 21, 2014 11:03 am
Full Name: Nikita Shestakov
Location: Prague
Contact:

Re: Powershell script to forward alarms

Post by Shestakov »

Try to use quotation marks:

Code: Select all

Powershell.exe “file name” ‘%1’

sandsturm
Expert
Posts: 161
Liked: 13 times
Joined: Mar 23, 2015 8:30 am
Contact:

Re: Powershell script to forward alarms

Post by sandsturm »

Hi Shestakov

It works now with the quotation marks well. I'm struggling with the next problem. If I type in such an action directly into the value field of the alarm setting in this format:

Code: Select all

powershell.exe C:\admin\scripts\Veeam_alarm.ps1 '%1' '%2' '%3' '%4' '%5' '%6' '%7'
it works fine. But now I want to configure this notification action for all my alarms, i found the link https://www.veeam.com/kb1547 to set my action for all alarms. If I try the following:

Code: Select all

Update Alarm Set actions = '<Actions><SendMail Value="admin@company.net"/><RunScript Value="powershell.exe C:\admin\scripts\Veeam_alarm.ps1"/></Actions>'
it works fine, but if I try to add the parameters %1 %2... as following:

Code: Select all

update monitor.Alarm 
set actions = '<Actions><RunScript Value="powershell.exe C:\admin\scripts\Veeam_alarm.ps1 ''%1'' ''%2'' ''%3'' ''%4'' ''%5'' ''%6'' ''%7''"/><SendMail Value="admin@company.net"/></Actions>'
and I check the values afterwards in Veeam monitor, all alarms are updated, but only with the following string:
powershell.exe C:\admin\scripts\Veeam_alarm.ps1

the parameters %1 %2... are not sat yet. We tried above command with different quotation marks as " or ' or as &quot; but we were unsuccessful. Do you have an idea?

thx,
sandsturm

Shestakov
Expert
Posts: 7328
Liked: 773 times
Joined: May 21, 2014 11:03 am
Full Name: Nikita Shestakov
Location: Prague
Contact:

Re: Powershell script to forward alarms

Post by Shestakov »

What product version are you at? In update 4 we added new tab for alarms called "Actions". Do you run scripts under the "Actions" tab or "Notifications" one?

sandsturm
Expert
Posts: 161
Liked: 13 times
Joined: Mar 23, 2015 8:30 am
Contact:

Re: Powershell script to forward alarms

Post by sandsturm »

I have installed update 4 and I tried to run the script in the Notifications tab. Should I use the Actions tab instead? The above command with the "update alarm set" affects the Notifications tab and not the Actions tab, therefore I tried to do it there...

thx,
sandsturm

Shestakov
Expert
Posts: 7328
Liked: 773 times
Joined: May 21, 2014 11:03 am
Full Name: Nikita Shestakov
Location: Prague
Contact:

Re: Powershell script to forward alarms

Post by Shestakov »

This script works fine in my lab:

Code: Select all

update monitor.Alarm 
set actions = '<Actions><RunScript Value="powershell.exe C:\admin\scripts\Veeam_alarm.ps1 ''%1'' ''%2'' ''%3'' ''%4'' ''%5'' ''%6'' ''%7''"/><SendMail Value="admin@company.net"/></Actions>'
You can just copy actions of one alarm to the others

Code: Select all

 update [monitor].[Alarm]
  set [actions] = a.[actions]
  from (select * from [monitor].[Alarm]) a
  where a.[alarm_id] = ?
Where ? is an alarm_id of the alarm with correct "actions" field.

ctalbot
Veeam Software
Posts: 54
Liked: 18 times
Joined: Oct 19, 2016 2:14 pm
Full Name: Carlos Talbot
Location: Chicago, IL
Contact:

Re: Powershell script to forward alarms

Post by ctalbot »

I'm having an issue passing parameters to a batch script. Using the example code above by sandstrum it appears only the timestamp parameter is coming through. All other parameters are blank. This is on a W2K16 server with Veeam One 9.5U4. I've tried it in the notification and actions tab with the same result. Anyone else experiencing this?

Code: Select all

C:\scripts>type ONEalarm.log
Alarmname:
Summary:
Node:
Summary:
Date: 11:13:43.39
OldStatus:
ID:
--------------

ctalbot
Veeam Software
Posts: 54
Liked: 18 times
Joined: Oct 19, 2016 2:14 pm
Full Name: Carlos Talbot
Location: Chicago, IL
Contact:

Re: Powershell script to forward alarms

Post by ctalbot » 1 person likes this post

You can disregard. I got this to work by using the example powershell syntax above within the notification tab:

Code: Select all

powershell.exe C:\scripts\pass_args.ps1 '%1' '%2' '%3' '%4' '%5' '%6' '%7'

sandsturm
Expert
Posts: 161
Liked: 13 times
Joined: Mar 23, 2015 8:30 am
Contact:

Re: Powershell script to forward alarms

Post by sandsturm »

I have to come back to this topic with VeeamONE event IDs. It's great that these Event ID's are now possible in Veeam one, but I have the following issue with it:

We send events thrown by Veeam ONE to our ServiceManagement system and therefore we have to rely on the eventID which is created from Veeam ONE. We have different Backupjobs for Backup with Veeam agents (Windows and Linux). Unfortunately, there is only one Event ID thrown for different (Agent)-Backup jobs by VeeamONE. This leads to the fact, that we just see one event in our service managment system, although multiple backup jobs failed. Do you think it's possible to change that behavior that every backup job has its own VeeamONE event ID?

thx
sandsturm

Vitaliy S.
Product Manager
Posts: 24262
Liked: 1865 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: Powershell script to forward alarms

Post by Vitaliy S. »

Right now it is not possible, but let me run this by our dev team and I will log a CR for our next updates.

sandsturm
Expert
Posts: 161
Liked: 13 times
Joined: Mar 23, 2015 8:30 am
Contact:

Re: Powershell script to forward alarms

Post by sandsturm »

thanks a lot, that would help.
By the way: I'm not sure if this is only for Agent Backupjobs, or if this "problem" also occures for "standard" Backup jobs...

Vitaliy S.
Product Manager
Posts: 24262
Liked: 1865 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: Powershell script to forward alarms

Post by Vitaliy S. »

We will check this out too, but most likely the ID is assigned to the job type/alarm and is kept the same.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests