Alarm Filter deletion and creation (at user level) using REST/XML
search cancel

Alarm Filter deletion and creation (at user level) using REST/XML

book

Article ID: 389363

calendar_today

Updated On:

Products

Network Observability

Issue/Introduction

 From customerĀ“s request:
 
I want to add/delete alarm filters at user level only via REST, could you please give me a small example what REST command should I use to delete a filter and how to setup a new alarm filter from a XML file for a certain user?

What should be the XML definition contents?

Environment

Any supported Spectrum version

Resolution

Let's consider our user is represented by model 0x1000075b and it has one alarm filter configured called "only_critical_alarms".

We can retrieve their user preferences using the following REST call:

curl -k -u spectrum http://oneclick:8080/spectrum/restful/model/0x1000075b?attr=0x129ef

In the response we can find the attribute 0x129ef whose value is a XML representing the user preferences (highlighted in red):

-------------------------------

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<model-response-list xmlns="http://www.ca.com/spectrum/restful/schema/response" total-models="1" throttle="1" error="EndOfResults">
<model-responses>
<model mh="0x1000075b">
<attribute id="0x129ef">&lt;?xml version="1.0" encoding="UTF-8"?&gt;&#13;&lt;preferences&gt;&lt;alarm-manager&gt;&lt;named-alarm-filters type="com.aprisma.spectrum.app.alarm.client.preferences.NamedAlarmFiltersPreference"&gt;&lt;pref&gt;&lt;complex-filter&gt;&lt;name&gt;only_critical_alarms&lt;/name&gt;&lt;simple-filter&gt;&lt;primary-state&gt;primary-and-secondary&lt;/primary-state&gt;&lt;clearable-state&gt;clearable-and-not&lt;/clearable-state&gt;&lt;acknowledged-state&gt;acknowledged-and-not&lt;/acknowledged-state&gt;&lt;filter-symptoms&gt;true&lt;/filter-symptoms&gt;&lt;hide-severities&gt;&lt;suppressed /&gt;&lt;major /&gt;&lt;minor /&gt;&lt;initial /&gt;&lt;maintenance /&gt;&lt;normal /&gt;&lt;/hide-severities&gt;&lt;/simple-filter&gt;&lt;/complex-filter&gt;&lt;/pref&gt;&lt;/named-alarm-filters&gt;&lt;alarm-filter type="com.aprisma.spectrum.app.alarm.client.preferences.AlarmFilterPreference"&gt;&lt;pref&gt;&lt;current&gt;only_critical_alarms&lt;/current&gt;&lt;/pref&gt;&lt;/alarm-filter&gt;&lt;/alarm-manager&gt;&lt;console&gt;&lt;horz-div type="java.lang.Float"&gt;0.25&lt;/horz-div&gt;&lt;vert-div type="java.lang.Float"&gt;0.59972864&lt;/vert-div&gt;&lt;cloned-views type="com.aprisma.spectrum.app.console.client.ConsoleApp$ClonedViewPref"&gt;&lt;root /&gt;&lt;/cloned-views&gt;&lt;width type="java.lang.Float"&gt;0.75&lt;/width&gt;&lt;nav-state type="java.lang.Integer"&gt;1&lt;/nav-state&gt;&lt;contents-state type="java.lang.Integer"&gt;1&lt;/contents-state&gt;&lt;details-state type="java.lang.Integer"&gt;1&lt;/details-state&gt;&lt;height type="java.lang.Float"&gt;0.79978585&lt;/height&gt;&lt;/console&gt;&lt;/preferences&gt;&#13;
</attribute>
</model>
</model-responses>
</model-response-list>

-------------------------------

As you can see the XML is escaped ("<" is escaped with "&lt;", ">" is escaped with "&gt;" and carriage-return is escaped with "&#13;")

&lt;?xml version="1.0" encoding="UTF-8"?&gt;&#13;
&lt;preferences&gt;&lt;alarm-manager&gt;&lt;named-alarm-filters type="com.aprisma.spectrum.app.alarm.client.preferences.NamedAlarmFiltersPreference"&gt;&lt;pref&gt;&lt;complex-filter&gt;&lt;name&gt;only_critical_alarms&lt;/name&gt;&lt;simple-filter&gt;&lt;primary-state&gt;primary-and-secondary&lt;/primary-state&gt;&lt;clearable-state&gt;clearable-and-not&lt;/clearable-state&gt;&lt;acknowledged-state&gt;acknowledged-and-not&lt;/acknowledged-state&gt;&lt;filter-symptoms&gt;true&lt;/filter-symptoms&gt;&lt;hide-severities&gt;&lt;suppressed /&gt;&lt;major /&gt;&lt;minor /&gt;&lt;initial /&gt;&lt;maintenance /&gt;&lt;normal /&gt;&lt;/hide-severities&gt;&lt;/simple-filter&gt;&lt;/complex-filter&gt;&lt;/pref&gt;&lt;/named-alarm-filters&gt;&lt;alarm-filter type="com.aprisma.spectrum.app.alarm.client.preferences.AlarmFilterPreference"&gt;&lt;pref&gt;&lt;current&gt;only_critical_alarms&lt;/current&gt;&lt;/pref&gt;&lt;/alarm-filter&gt;&lt;/alarm-manager&gt;&lt;console&gt;&lt;horz-div type="java.lang.Float"&gt;0.25&lt;/horz-div&gt;&lt;vert-div type="java.lang.Float"&gt;0.59972864&lt;/vert-div&gt;&lt;cloned-views type="com.aprisma.spectrum.app.console.client.ConsoleApp$ClonedViewPref"&gt;&lt;root /&gt;&lt;/cloned-views&gt;&lt;width type="java.lang.Float"&gt;0.75&lt;/width&gt;&lt;nav-state type="java.lang.Integer"&gt;1&lt;/nav-state&gt;&lt;contents-state type="java.lang.Integer"&gt;1&lt;/contents-state&gt;&lt;details-state type="java.lang.Integer"&gt;1&lt;/details-state&gt;&lt;height type="java.lang.Float"&gt;0.79978585&lt;/height&gt;&lt;/console&gt;&lt;/preferences&gt;&#13;


If we unescape and format, we have this XML (you can use this web: https://www.freeformatter.com/xml-escape.html )

-------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<preferences>
<alarm-manager>
<named-alarm-filters type="com.aprisma.spectrum.app.alarm.client.preferences.NamedAlarmFiltersPreference">
<pref>
<complex-filter>
<name>only_critical_alarms</name>
<simple-filter>
<primary-state>primary-and-secondary</primary-state>
<clearable-state>clearable-and-not</clearable-state>
<acknowledged-state>acknowledged-and-not</acknowledged-state>
<filter-symptoms>true</filter-symptoms>
<hide-severities>
<suppressed/>
<major/>
<minor/>
<initial/>
<maintenance/>
<normal/>
</hide-severities>
</simple-filter>
</complex-filter>
</pref>
</named-alarm-filters>
<alarm-filter type="com.aprisma.spectrum.app.alarm.client.preferences.AlarmFilterPreference">
<pref>
<current>only_critical_alarms</current>
</pref>
</alarm-filter>
</alarm-manager>
<console>
<horz-div type="java.lang.Float">0.25</horz-div>
<vert-div type="java.lang.Float">0.59972864</vert-div>
<cloned-views type="com.aprisma.spectrum.app.console.client.ConsoleApp$ClonedViewPref">
<root/>
</cloned-views>
<width type="java.lang.Float">0.75</width>
<nav-state type="java.lang.Integer">1</nav-state>
<contents-state type="java.lang.Integer">1</contents-state>
<details-state type="java.lang.Integer">1</details-state>
<height type="java.lang.Float">0.79978585</height>
</console>
</preferences>

-------------------------------

Inspecting the XML you can find an entry <named-alarm-filters> for the "only_critical_alarms" alarm filter (highlighted in red).

If you remove that section, your XML will look like this (keep all the remaining parts of the XML because they represent the other user preferences):

-------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<preferences>
<alarm-manager>
<alarm-filter type="com.aprisma.spectrum.app.alarm.client.preferences.AlarmFilterPreference">
<pref>
<current>only_critical_alarms</current>
</pref>
</alarm-filter>
</alarm-manager>
<console>
<horz-div type="java.lang.Float">0.25</horz-div>
<vert-div type="java.lang.Float">0.59972864</vert-div>
<cloned-views type="com.aprisma.spectrum.app.console.client.ConsoleApp$ClonedViewPref">
<root/>
</cloned-views>
<width type="java.lang.Float">0.75</width>
<nav-state type="java.lang.Integer">1</nav-state>
<contents-state type="java.lang.Integer">1</contents-state>
<details-state type="java.lang.Integer">1</details-state>
<height type="java.lang.Float">0.79978585</height>
</console>
</preferences>

-------------------------------


Escape the XML (you can use this web: https://www.freeformatter.com/xml-escape.html ):

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;preferences&gt;&lt;alarm-manager&gt;&lt;alarm-filter type=&quot;com.aprisma.spectrum.app.alarm.client.preferences.AlarmFilterPreference&quot;&gt;&lt;pref&gt;&lt;current&gt;only_critical_alarms&lt;/current&gt;&lt;/pref&gt;&lt;/alarm-filter&gt;&lt;/alarm-manager&gt;&lt;console&gt;&lt;horz-div type=&quot;java.lang.Float&quot;&gt;0.25&lt;/horz-div&gt;&lt;vert-div type=&quot;java.lang.Float&quot;&gt;0.59972864&lt;/vert-div&gt;&lt;cloned-views type=&quot;com.aprisma.spectrum.app.console.client.ConsoleApp$ClonedViewPref&quot;&gt;&lt;root/&gt;&lt;/cloned-views&gt;&lt;width type=&quot;java.lang.Float&quot;&gt;0.75&lt;/width&gt;&lt;nav-state type=&quot;java.lang.Integer&quot;&gt;1&lt;/nav-state&gt;&lt;contents-state type=&quot;java.lang.Integer&quot;&gt;1&lt;/contents-state&gt;&lt;details-state type=&quot;java.lang.Integer&quot;&gt;1&lt;/details-state&gt;&lt;height type=&quot;java.lang.Float&quot;&gt;0.79978585&lt;/height&gt;&lt;/console&gt;&lt;/preferences&gt;