DX Infrastructure Management

CA on CA Tech Tip - Using the UIM API to put devices in maintenance mode 

02-28-2018 05:36 PM

Hi Community,

 

One of the most common tasks we have is suppressing alarms for planned outages using maintenance mode. It can be tedious to do this manually. Linked is an example of how you can do it using the UIM API. You are welcome to have the code and make modifications / improvements to it. I am sure the real programmers will take one look at what I have written and run screaming to fix it. 

 

This is based on a library of Python  functions available in GitHub as cauimws.py. The complete code is available in GitHub as well as maintenancemode.py. Let us explain what it is doing.

 

Start by setting up some logging the levels include logging.DEBUG (most logging) to logging.CRITICAL (least logging)

# Init logging level
logging.basicConfig(level=logging.DEBUG)

 

Now let us build the data needed to create our maintenance schedule. In this case we are creating a 1 time schedule for March 3, 2018 at 4PM New York time and it will last for 4 hours

# Set initial schedule values
name = "March Windows Patching"
desc = "March Windows Patching"
# Date is March 3rd 2018 4:00 PM
start_str = '2018-03-03-16-00-00'
duration = 4
timezone = 'America/New_York'

 

We now need to get information about the UIM REST API from a configuration file as well as the list of systems we want to put in maintenance mode

# Get filename with systems to put in maintenance mode
systems_list_file = config.get('data', 'systems_list_file')

# Init the dict with UIM REST API information
uim_ws = {}
uim_ws['user'] = config.get('uim_ws', 'user')
uim_ws['password'] = config.get('uim_ws', 'password')
uim_ws['url'] = config.get('uim_ws', 'url')
uim_ws['domain'] = config.get('uim_ws', 'domain')
uim_ws['pri_hub'] = config.get('uim_ws', 'primary_hub')
uim_ws['mm_robot'] = config.get('uim_ws', 'mm_robot')

 

The configuration file config.ini is in the sample format below

[uim_ws]
user = uim_bus_user
password = uim_bus_user_password
domain = cauimdom
primary_hub = cauimprihub
mm_robot = primary_robot

[data]
systems_list_file = systems.txt

 

The system.txt file simply has 1 system on each line. We use the IP address of the machine to find it in DNS if that fails we search UIM using the name.

Now that we have all the data we need let us create the maintenance schedule by passing the uim_ws (UIM REST API information), the name of the schedule, the description, the start time, the duration and the timezone we want it to honor

# Create maintenance schedule
schedule_id = create_mm_schedule(uim_ws, name, desc, start, duration, timezone)

 

The above returns a schedule id. Let us get the list of systems from the file and use that to find the cs_id (see the cm_computer_system table in the UIM DB)

# Get the list of systems to put in maintenance mode and convert to cs_id list
cs_ids = get_systems_list(systems_list_file, uim_ws)

 

With the list of cs_id in returned we will then add them to maintenance schedule using the id from above

# Add the list of systems as cs_ids to the maintenance mode schedule
if add_cs_to_mm_schedule(uim_ws, schedule_id, cs_ids):
logging.info('Successfully add systems to maintenance')
else:
logging.critical('Failed to add systems to maintenance mode')

 

That's it. The real code is available in GitHub cauimws/maintenancemode.py at master · adgayle/cauimws · GitHub 

 

Feel free to use it and make improvements. This is very generic and can be improved to accept the options as parameters instead of hard coding them. This is just to get you started.

Statistics
0 Favorited
2 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Comments

05-30-2018 02:40 PM

Hi rtirak

 

I am happy to hear that you are able to find benefit from the examples. Unfortunately, I have never written anything for the Set a Single Probe Configuration Value. We use packages for pretty much all the changes (we are using MCS for new tenants). I received your other note via and will post sample code for how we push packages via the API.

05-30-2018 08:58 AM

Alquin

 

Do you happen to have an example or something in python (like the others you have listed on GitHub) where you call the set single probe configuration value and set a new value? I am able to get the values but have not been able to set a value. I have been using/modifying your python and they have been very helpful however I can't seem to get anything written that works to "Set a Single Probe Configuration Value"

 

I am going to be using this in automating our server decommission process. Figured I would reach out and see if you had worked on something like this or could provide me some type of example etc.

 

Thanks,


Bob

Related Entries and Links

No Related Resource entered.