Managing the - Actions - database

Latest response

I have inherited a fairly seasoned Satellite environment which runs rather well.

Lately I have been doing some regression testing and validation and attempting to use the output under Schedule | Actions.

Unfortunately I do not believe that anyone has ever archived (nor deleted) a single event in the history of the server and the number of events are over 100,000 !  When I try to "Select All" my Satellite appears to hang and then I get a JVM core.

Does anyone know of a way to use the API to manage the events?  Namely to archive then delete these events.

Thanks in advance for any advice!

Responses

Yes there are APIs available to list, archive and delete actions. List of API's which you can use to list, archive and delete the actions can been seen by going to http://your-satellite-fqdn/rhn/apidoc/handlers/ScheduleHandler.jsp

So in short APIs that you might want to use are :

  1. listAllActions
  2. archiveActions
  3. listArchivedActions
  4. deleteActions

 

This feature and APIs were recently release  under errata http://rhn.redhat.com/errata/RHBA-2013-0583.html . Do ensure this or latest errata is installed on your satellite.

Paresh

Thanks - I had not noticed the "deleteActions" in the docs I had found.

I used their example as a template.  If I attempt to display all the completed actions, the JVM will core. :-(

I am an absolute beginner with Python/Perl/etc.. (I decided to be sysadmin and not a developer for a reason ;-)

The example below will work, but if I attempt to use the section now commented out, it will fail.  I will probably need to open a case and ask them how to run sql against the DB to clear out the entries.

#!/usr/bin/env python
import xmlrpclib

SATELLITE_URL = "http://rhnsat01.corp.company.com/rpc/api"
SATELLITE_LOGIN = "satadmin"
SATELLITE_PASSWORD = "password"

client = xmlrpclib.Server(SATELLITE_URL, verbose=0)

key = client.auth.login(SATELLITE_LOGIN, SATELLITE_PASSWORD)

# CHANGE THINGS AFTER THIS LINE
list = client.schedule.listArchivedActions(key)
for record in list:
   print record.get('id')

#list = client.schedule.listCompletedActions(key)
#for record in list:
#  print record.get('id')
  #client.schedule.cancelActions(list)

# CHANGE THINGS BEFORE THIS LINE
client.auth.logout(key)

On RHN Satellite, running a SQL query against the DB and deleting records is not recommend and not supported. Instead I will try to help you with the python code.

Here is the example of how you can use API to delete the actions.

list = client.schedule.listArchivedActions(key)
action_ids=[]
for action in list:
    action_ids.append(action['id'])

del_result=client.schedule.deleteActions(key,action_ids)
 

Let me know if this helps you get started.

Paresh

In addtion to deleteAction, here is an example to archive failed, completed actions and then delete all archived actions.

#archive all Failed Actions
failed_list = client.schedule.listFailedActions(key)
action_ids=[]
for action in failed_list:
    action_ids.append(action['id'])

archive_result=client.schedule.archiveActions(key,action_ids)

#archive all Completed Actions
completed_list = client.schedule.listCompletedActions(key)
action_ids=[]
for action in completed_list:
    action_ids.append(action['id'])

archive_result=client.schedule.archiveActions(key,action_ids)

#delete all Archived Actions
archived_list = client.schedule.listArchivedActions(key)
action_ids=[]
for action in archived_list:
    action_ids.append(action['id'])

del_result=client.schedule.deleteActions(key,action_ids)
 

Hope this  helps.

Paresh

Thanks Paresh!  I will try this later and let you know how it goes.

 

Seeing the actual code makes understanding how it works a bit easier.

Thanks again for your assistance and advice.

I modified the approach (slightly).  If I was to build an array with all 116,000 actions, or attempt to, using the entire stack - it would still create a JVM core. 

So, I did the following:

#!/usr/bin/env python
import xmlrpclib
import time

SATELLITE_URL = "http://XXX/rpc/api"
SATELLITE_LOGIN = "XXX"
SATELLITE_PASSWORD = "XXX"client = xmlrpclib.Server(SATELLITE_URL, verbose=0)

key = client.auth.login(SATELLITE_LOGIN, SATELLITE_PASSWORD)

###############################
# CHANGE THINGS AFTER THIS LINE
#

## Delete all Failed Actions
x = "Deleting all Failed Actions"
print(x)
failed_list = client.schedule.listFailedActions(key)
action_ids=[]
for action in failed_list:
    action_ids.append(action['id'])

archive_result=client.schedule.archiveActions(key,action_ids)

## Archive all Completed Actions
## Generate an Array of size (max_num_ids) and purge it
x = "Archiving all Completed Actions"
print(x)
counter = 0
max_num_ids = 20
archived_list = client.schedule.listCompletedActions(key)
action_ids=[]
for action in archived_list:
    print action.get('id')
    action_ids.append(action['id'])
    counter = counter + 1
    if counter == max_num_ids:
        del_result=client.schedule.archiveActions(key,action_ids)
        time.sleep(.5)
        action_ids=[]
        counter = 0

## Delete all Archived Actions
## Generate an Array of size (max_num_ids) and purge it
x = "Deleting all Completed Actions"
print(x)
counter = 0
max_num_ids = 30
archived_list = client.schedule.listArchivedActions(key)
action_ids=[]
for action in archived_list:
    print action.get('id')
    action_ids.append(action['id'])
    counter = counter + 1
    if counter == max_num_ids:
        del_result=client.schedule.deleteActions(key,action_ids)
        time.sleep(.5)
        action_ids=[]
        counter = 0

##
## CHANGE THINGS BEFORE THIS LINE
###############################
client.auth.logout(key)
 

Good to know. I assume your modified script helped you clean up the archived actions. On one of my test satellites I had around ~5000 archived actions. I didn't have to limit the deletion, all of them deleted in a single api call. You might want to increase the counter from 20/30 to 1000's and see how it goes.

Paresh

Hmmm I am getting an error with this.

Deleting all Failed Actions
Archiving all Completed Actions
Traceback (most recent call last):
  File "./deleteactions.py", line 33, in ?
    archived_list = client.schedule.listCompletedActions(key)
  File "/usr/lib64/python2.4/xmlrpclib.py", line 1096, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib64/python2.4/xmlrpclib.py", line 1383, in __request
    verbose=self.__verbose
  File "/usr/lib64/python2.4/xmlrpclib.py", line 1147, in request
    return self._parse_response(h.getfile(), sock)
  File "/usr/lib64/python2.4/xmlrpclib.py", line 1286, in _parse_response
    return u.close()
  File "/usr/lib64/python2.4/xmlrpclib.py", line 744, in close
    raise Fault(**self._stack[0])
xmlrpclib.Fault: <Fault -1: 'redstone.xmlrpc.XmlRpcFault: unhandled internal exception: null'>

Actually just ran it again after restarting Satellite and it is running fine. Thanks!

Glad to hear it worked.

I should have mentioned that there is a possibility that you will encounter a ActionID that is not manageable via the API - which can throw the errors you had experienced.  At that point, you are best of contacting Red Hat to have them assist you in the remainder of the clean-up.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.