[Spacewalk-list] client side check file managed by spacewalk
Josh.Mullis at cox.com
Josh.Mullis at cox.com
Fri Oct 21 20:05:18 UTC 2011
Jason,
This is client-based info, so not sure if this will help...
On all non-binary files we have in spacewalk, we put this line at or near the top to let us know it came from spacewalk...
## Spacewalk Managed File ##
When we are running our config mgmt scripts, we use "rhncfg-client verify <file_name>".
This command tells us if the file is changed or doesn't exist.
So you could do a simple "for" loop through all spacewalk files visible to that client system like so:
for i in `rhncfg-client list`
do
rhncfg-client verify $i
done
Hope this helps.
-Josh
-----Original Message-----
From: spacewalk-list-bounces at redhat.com [mailto:spacewalk-list-bounces at redhat.com] On Behalf Of Jason M. Nielsen
Sent: Friday, October 21, 2011 12:59 PM
To: spacewalk-list at redhat.com
Subject: [Spacewalk-list] client side check file managed by spacewalk
Spacewalk 1.5
Trying to determine the best method of determining if a file was
deployed to a client, from the command, while on the client. For
instance, Currently I do a lookupFileInfo, calculate a local md5sum,
compare that to the SW md5sum and report. This does not really say its
been deployed though and only that it is the same. Thought I saw the
later in the gui but cant seem to find it.
Is there some record such as a system+file pair showing it was indeed
deployed available via the api?
Also I think I might have run into a bug but its more likely my
misunderstanding. If I query a file that is "locally managed"
lookupFileInfo returns one entry in the array. If I look up any file in
any channel (not sandbox) I get 2 entries in the array that are
duplicates. It doesnt matter in what order or what files, systems or
channels etc. If its local, one entry. If its another channel, two
entries. Also note that the double entries are for the same channel.
Code and a test output follows:
#!/usr/bin/python
import xmlrpclib
import getpass
import sys
import hashlib
from socket import gethostname
def md5sum(filename):
m = hashlib.md5()
try:
fin0 = open(filename,"rb")
except IOError:
print "Unable to open the file:", filename
return
file_content = fin0.readlines()
fin0.close()
for line in file_content:
m.update(line)
return m.hexdigest()
file_list = list(sys.argv[1:len(sys.argv)])
SATELLITE_URL = "https://spacewalk/rpc/api"
SATELLITE_LOGIN = "Administrator"
SATELLITE_PASSWORD = getpass.getpass(prompt='Password: ')
client = xmlrpclib.Server(SATELLITE_URL, verbose=0)
key = client.auth.login(SATELLITE_LOGIN, SATELLITE_PASSWORD)
hostname = gethostname()
hosts = client.system.getId(key,hostname)
if len(hosts) > 1:
print "ERROR: Multiple profiles!"
print "There appear to be multiple profiles for this hostname."
print "Please correct this and reissue command."
exit
host_id = hosts[0].get('id')
file_info = client.system.config.lookupFileInfo(key,host_id,file_list,1)
for file in file_info:
print file.get('path')
print " Hostname : ", hostname
for file in file_info:
path = file.get('path')
localhost_md5sum = md5sum(path)
server_md5sum = file.get('md5')
print " File : ", path
print " Channel : ", file.get('channel')
print "Localhost MD5 : ", localhost_md5sum
print " Server MD5 : ", server_md5sum
if localhost_md5sum == server_md5sum:
print " Managed : Yes"
else:
print " Managed : No"
client.auth.logout(key)
==========================================
root at leonov:~/bin/spacewalk-scripts/dev# ./is_file_managed.py
/etc/cron.d/spacewalk_rhncheck /etc/cron.d/spacewalk_archive_actions
/etc/resolv.conf
Password:
/etc/cron.d/spacewalk_rhncheck
/etc/cron.d/spacewalk_rhncheck
/etc/cron.d/spacewalk_archive_actions
/etc/resolv.conf
/etc/resolv.conf
Hostname : leonov
File : /etc/cron.d/spacewalk_rhncheck
Channel : Global RHEL
Localhost MD5 : 195545c0101e94851adc5d95899a951b
Server MD5 : 195545c0101e94851adc5d95899a951b
Managed : Yes
File : /etc/cron.d/spacewalk_rhncheck
Channel : Global RHEL
Localhost MD5 : 195545c0101e94851adc5d95899a951b
Server MD5 : 195545c0101e94851adc5d95899a951b
Managed : Yes
File : /etc/cron.d/spacewalk_archive_actions
Channel : leonov
Localhost MD5 : a49367ea0a2a330a6f76317055de4eca
Server MD5 : a49367ea0a2a330a6f76317055de4eca
Managed : Yes
File : /etc/resolv.conf
Channel : Global RHEL
Localhost MD5 : 08a44dc564fc565184f5705736ba0b77
Server MD5 : 08a44dc564fc565184f5705736ba0b77
Managed : Yes
File : /etc/resolv.conf
Channel : Global RHEL
Localhost MD5 : 08a44dc564fc565184f5705736ba0b77
Server MD5 : 08a44dc564fc565184f5705736ba0b77
Managed : Yes
_______________________________________________
Spacewalk-list mailing list
Spacewalk-list at redhat.com
https://www.redhat.com/mailman/listinfo/spacewalk-list
More information about the Spacewalk-list
mailing list