Did you know you can update CA Spectrum user attributes using Web Services?
Application Program Interfaces (APIs) have become a critical part of the business to ingest and extract any kind of data from any online resource. APIs are highly beneficial to network management as well as automation, integration and personalization of systems.
CA Spectrum provides a comprehensive API functionality that can be leveraged by users or developers to integrate with any 3rd party solution. Some of the CA Spectrum network management elements you can access via APIs are devices, events, models, attributes, landscapes, alarms, subscriptions and associations.
In this tutorial, we will walk through how to read and update user attributes from/to CA Spectrum models. This kind of enrichment is extremely useful to populate your CA Spectrum inventory with user or business information such as “service associated to the device”, “virtual DC of the device”, owner, purpose or any other variable that is relevant for your business.
Reading a single network management attribute
Reading a single attribute of a CA Spectrum model is very straight forward. We will use the “model” API resource for this purpose.
The “model” resource is documented in the Web Services API Reference Guide in CA Spectrum documentation. Basically, this resource is used to create or delete a model and to read or modify model attributes.
The API URL to read an attribute requires 2 parameters:
- Model Handle
- Attribute ID
NOTE: The model handle and attribute ID can be fetched from the Attributes tab in OneClick console or via API (http://<OCserver>:<port>/spectrum/restful/devices?attr=0x1006e)
The API method to use is a “GET” and the URL is:
The expected output is displayed below. As can be seen, it returns the model handle, attribute ID and the current value (“MadridVDC” for this example).
Figure 1: API response to query a single model attribute.
NOTE: CA Spectrum Web Services API is hosted by and sits on top of the OneClick server so our API calls will be run against the OneClick server.
Updating a single network management attribute
So let’s make an update that our router is now moved to a different VDC and we want to change the attribute “Location” programmatically. We will trigger the single attribute update URL.
The update URL requires 3 parameters instead of 2:
- Model Handle
- Attribute ID
- New value
And the method to use is a “PUT”. This is very important, other methods (GET, POST,…) will fail:
The expected output is displayed below. Note the success message that can be processed via script for validation:
Figure 2: API response of Model attribute update.
Mass populate network management attributes
Reading or updating a single model is useful but not very practical for large environments. This section explains how to perform a mass network management update. There are 2 main mechanism to achieve the mass update:
- Use the “models” resource to retrieve and update models and attributes. The models resource operates on groups of models. The models resource is very powerful and lets you provide an XML document with a search criteria with the models to retrieve and update. There is more information in the CA Spectrum DocOps, under section “Web Services API Reference”
- Use a simple script that reads from a CSV file and perform the mass update.
We will cover option #2 in this section. Let’s take a look at how we can update 3 devices from a CSV file.
The structure of our CSV file can be: “ModelHandle”,”AttributeId”,”AttributeValue”. In this example, we will update 3 models (column 1) with 3 different attributes (column 2). The new values for these attributes is in column 3:
0x100449,0x11564,Router to be replaced
The attribute names from column 2 are “Location”, “Notes” and “USER_AssetOwner”.
The script to use for this exercise is shown below. Basically it reads the seed CSV file and it sends a curl “PUT” request to the CA Spectrum API.
# CSV Separator
# Basic Output in Terminal Window
echo "Mass update started..."
# Read the CSV
while read mh attid newvalue
echo "Updating attributeId $attid from MH $mh with value '$newvalue'"
#Replace empty spaces with %20 for new value string
# actual call
curl -X PUT -v -u $OCUSER:$OCPASSWD "$BASEURL$mh?attr=$attid&val=$newvalue"
done < $INPUTFILE
This network management script is for explanatory purposes only. For production use, we suggest the hard-coded user and password and pass it via parameters to the script to improve security.
NOTE: Each curl command will output a “Success” or error code so we can easily validate that the attributes are being updated.
The updated attributes can also be validated in CA Spectrum OneClick - attribute tabs:
Figure 3: OneClick Attributes Tab displaying the updated attribute.
We covered how to run the update of single attributes as well as mass bulk updates. This example sets a foundation that you can use to build more complex queries or updates to fit your needs. Enriching CA Spectrum network management models is easy and it can add value to your organization.
One last tip before we finish this tutorial: large data requests across multiple clients can cause performance degradation so remember to start small and be aware that massive updates can impact the SpectroSERVER.
CA Technologies has more than 20 years of experience in the application performance, infrastructure and NetOps management domains. CA Spectrum offers the robust, comprehensive and sophisticated event and network fault management capabilities that network operations teams require to achieve digital and network transformation success.
Learn more here.