Need to extract Server name and Content View from the HOST collection
Hello Guru's,
I have Satellite running 6.2.11. I have host Collection called "PROD" and I am trying to extract "Server name" and "content View" information.
I am able to use following "hammer" comand but I only get the Server names and not the content view.
hammer --output csv host-collection hosts --name "Prod" --organization {Org_name} >>> With this command I get the ID and Names.
Any help is appreciated.
Regards,
MP
Responses
probably not a direct way to correlate host collections and content hosts (though that seems intuitive, and I expect that the more they combine the host/content-host relationship it will be easier to extract this info.
An API call w/ python would be faster, but for the sake of the question
for host in $(hammer --output csv host-collection hosts --name "<host-collection>" --organization "<organization>"|awk -F, '{print $1}')
do
hammer --output csv content-host info --id ${host}|awk -F, '{print $1,$2,$6}'
done
Assuming you are on Satellite 6.2.2 or newer, hammer csv can do this. Example follows (my Organization is named RedHat and my host collection is named Production)
hammer csv content-hosts --export \
--file prod.csv \
--verbose \
--organization RedHat \
--search 'host_collection = Production'
This will give you a CSV output which contains a number of fields you'd care about including
Name,Organization,Environment,Content View,Host Collections,Virtual,Guest of Host,OS,Arch,Sockets,RAM,Cores,SLA,Products,Subscriptions
You can select the colums you want, and delete the remainder.
ADVANCED. You can tweak hammer csv to provide a custom report with just the fields in it that you want. Add the following to your hammer configuration /etc/hammer/cli.modules.d/csv.yml or ~/.hammer/cli_config.yml
:csv:
:enable_module: true
:columns:
:content-hosts:
:define:
- :name: Content View
:json:
- content_facet_attributes
- content_view_name
- :name: Lifecycle Environment
:json:
- content_facet_attributes
- lifecycle_environment_name
Then you can run
hammer csv content-hosts \
--export \
--columns "Name,Content View,Lifecycle Environment" \
--file custom-report.csv \
--search 'host_collection = Production'
And i'd get output like:
Name,Content View,Lifecycle Environment
kvm01.example.com,RHEL7_Infra,Infrastructure
auth02.example.com,RHEL7_Infra,Infrastructure
capsule-1.example.com,Default Organization View,Library
logging.example.com,RHEL7_Infra,Infrastructure
More on this in Subscription-manager for the former Red Hat Network User: Part 12 - Subscription Reporting Tools
Just for the fun, let me add one more solution:
#!/bin/bash
for CollectionName in $(hammer --output csv host-collection list | grep -v ^ID | awk -F, '{print $2}')
do
for Name in $(hammer --output csv host-collection hosts --name ${CollectionName} | grep -v ^ID | awk -F, '{print $2}')
do
hammer --output csv content-host info --name ${Name} | grep -v ^Name | awk -F, '{print $1" "$6}'
done
done
save it to a file name say: host-collection-content-view-report.sh chmod it run it get the following:
root@sat ~]# ./host-collection-content-view-report.sh
doh1.dev.org RHEL7_CV
Lots a ways to skin the cat.
Hi Rich, if I have content view like PROD RHEL 6 PROD RHEL 7 PRDO RHEL 5 .... I am trying to put in --search 'host_collection = Production'
--search "host_collection =PROD%" or "PROD*" but no luck
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
