[Spacewalk-list] Query current OSA clients

Matthew Madey mattmadey at gmail.com
Tue Jan 20 18:31:46 UTC 2015


Here is a python script I wrote for reporting. It will return the hostname
and OSA status for every registered client, and is much faster than using
spacecmd. You could wrap it in a shell script to return only the systems
you're looking for, or if you're familiar with python just adjust the code
to filter the ones that are "online".  You will need to setup a
configuration file containing the username and password to use when
querying (If you are using Spacewalk 2.2, I'd recommend making this a
read-only API user for the sake of security) Hope this helps.

Create file: /etc/rhn/rhn-api-user.conf

File contents:

[Spacewalk]
spw_server = yourserver.example.com
spw_user   = username
spw_pass   = password


Here is the python script:

#!/usr/bin/python

import xmlrpclib
import subprocess
import os
import sys
import ConfigParser

cfg_file="/etc/rhn/rhn-api-user.conf"
config = ConfigParser.ConfigParser()
try:
    config.read (cfg_file)
except:
    print "Could not read config file %s." % cfg_file
    sys.exit(1)
try:
    spw_server = config.get ('Spacewalk', 'spw_server')
    spw_user = config.get ('Spacewalk', 'spw_user')
    spw_pass = config.get ('Spacewalk', 'spw_pass')
except:
    print "The file %s seems not to be a valid config file." %
options.cfg_file
    sys.exit(1)


SATELLITE_URL = "http://{0}/rpc/api".format(spw_server)
SATELLITE_LOGIN = spw_user
SATELLITE_PASSWORD = spw_pass
client = xmlrpclib.Server(SATELLITE_URL, verbose=0)
key = client.auth.login(SATELLITE_LOGIN, SATELLITE_PASSWORD)

print "hostname,status"
systems = client.system.listSystems(key)
for system in systems:
        hostname = system['name']
        id = system['id']
        details = client.system.getDetails(key, id)
        status = details['osa_status']
        print "%s,%s" % (hostname, status)

client.auth.logout(key)



On Tue, Jan 20, 2015 at 11:02 AM, Justin Edmands <j.edmands at sagedining.com>
wrote:

> Hey Spacewalkers,
> I am attempting to query all of the systems that are currently checking in
> via OSAD. I have been using a fairly inefficient spacecmd command to make
> this work for now.
>
>             [12:00:13][justin at justindev1:~]# spacecmd system_details S0*
> | grep -e "Name" -e "OSA" >> OSA_status.out ; grep online OSA_status.out |
> wc -l
>
> the S0 just happens to be the first two characters in the names I want to
> query. In the end it does a word count to determine how many are "online"
>
> Any better way to do this? This takes about 2-5 minutes when run against a
> list of about 500 clients.
>
>
> _______________________________________________
> Spacewalk-list mailing list
> Spacewalk-list at redhat.com
> https://www.redhat.com/mailman/listinfo/spacewalk-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/spacewalk-list/attachments/20150120/4b26d52d/attachment.htm>


More information about the Spacewalk-list mailing list