cancel
Showing results for 
Search instead for 
Did you mean: 

closing an alert

 
SOLVED
Go to solution
BradV
Trusted Contributor

closing an alert

I can retrieve active alerts with: 

ACTIVE=$(curl --insecure \
              --header "X-API-Version: ${currentVersion}" \
              --header "auth: ${sessionID}" \
              --request GET ${OneView}/rest/alerts?start=0&count=-1&filter="alertState EQ 'Active'")

Some of the alerts are on older servers that are no longer under maintenance.  I'm trying to clear the alert with: 

USER=Brad
NOTE='Server no longer under maintenance'
DATA='{ "alertState": "Cleared", "assignedToUser": "'${USER}'", "alertUrgency": "None", "notes": "'${NOTE}'", "eTag": "" }'
ALERTURI='/rest/alerts/2177698'
curl --insecure \
     --header "content-type: application/json" \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --header "If-Match" '*'" \
     --data "${DATA}" \
     --request PUT "${OneView}${ALERTURI}" | jq -r '.'

but am getting back "parse error: Invalid numeric literal at line 1, column 10."  I can echo ${DATA} | jq -r '.' and get back a valid JSON object.

Any ideas?

 

4 REPLIES 4
AmRa
HPE Pro

Re: closing an alert

Greetings,

You can clear “active” alerts through PowerShell.

Please find the steps to clear OneView “active” alerts through PowerShell.

1. Download and install HPE.OneView.XX.PowerShell.Library.exe from below link. (where XX is OneView Version)

https://github.com/HewlettPackard/POSH-HPOneView/releases

2. Open PowerShell prompt and Check first what the execution policy is in this environment. If it is Restricted, set it to Unrestricted. Type:

Get-ExecutionPolicy

and press Enter. If it is Unrestricted, skip to the next step. If it is Restricted, type:

Set-ExecutionPolicy Unrestricted

Confirm with Y <Enter> and verify if it is Unrestricted now by typing again:

Get-ExecutionPolicy

3. Establish a connection with the appliance by executing below command:

Connect-HPOVMgmt -appliance <IP Address>

where <IP Address> is the IP address of your appliance on the network, and option -appliance is default for the first parameter (might be omitted).

You are asked to enter User (Administrator), Password (password), and optionally Authentication Domain (not used here). After a few seconds, a session is established and prompt changed to show the user and managed server.

4. Execute below command view/verify the “active” alerts.

Get-HPOVAlert -State active

5. Verify the active alerts and later execute below command to clear “active” alerts.

Get-HPOVAlert -State active | Remove-HPOVAlert -force


Accept or Kudo
BradV
Trusted Contributor

Re: closing an alert

I don't have any Windows systems.  So, no powershell.  I know you guys are big on powershell, be we have no Windows servers, workstations, desktops, etc in this enclave, just RHEL.  I'll take a look at the powershell scripts and see if they give me an idea.

BhaskarV
HPE Pro

Re: closing an alert

Hi @BradV 

Was able to get your script to work just with curl the way you have been using.
The problem here is similar to the other one you have with default-login-domain.

It seems to have to do with single quotes, double quotes, JSON and "curl" sensitivity.

The two fields that seem to give trouble are the single quotes around 'Server no longer under maintenance'

NOTE='Server no longer under maintenance'

as well as 

the extra "double quotes" in the --header below

--header "If-Match" '*'"

For it to work, this should be --header "If-Match '*'"
Remove the double quotes soon after If-Match. 

Here is what my command line looks like and works.

curl --insecure --header "content-type: application/json" --header "X-API-Version: 800" --header "auth:XYZ" --data '{ "alertState": "Active", "assignedToUser": "administrator", "alertUrgency": "None", "notes": "Server no longer under maintenance", "eTag": "" }' --header "If-Match '*'" --request PUT "https://myappliance.hpe.com/rest/alerts/5"

First get a command line like the above with all values substituted working.
Get all the singlq quote, double quote, URL encoding issues sorted. out.|
Then convert it to a script like the one you are trying to get working.

Regards,
Bhaskar


Accept or Kudo
BradV
Trusted Contributor
Solution

Re: closing an alert

Hi Bashkar,

The extra double quote in the if-match line was a typo.  On my system I had 

 

--header "If-Match: '*'"

 

All of the other headers have a "Name" followed by a colon and then a "Value."  I expected the same for this header.  But once I removed the colon, it worked!  It worked either if I got the correct eTag, or left the eTag empty.  WIth getting the eTag, I used: 

 

ALERTURI='/rest/alerts/2177698'
ETAG=$(curl --insecure \
            --header "X-API-Version: ${currentVersion}" \
            --header "auth: ${sessionID}" \
            --request GET "${OneView}${ALERTURI}" | jq -r '.eTag')
USER=Brad
NOTE='Server no longer under maintenance'
DATA='{ "alertState": "Cleared", "assignedToUser": "'${USER}'", "alertUrgency": "None", "notes": "'${NOTE}'", "eTag": "'${ETAG}'" }'
echo ${DATA} | jq -r '.'
curl --insecure \
     --header "content-type: application/json" \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --header "If-Match '*'" \
     --data "${DATA}" \
     --request PUT "${OneView}${ALERTURI}" | jq -r '.'

 

can also just set ETAG='' and it works. 

Thanks so much for the help!