Need to extract Server name and Content View from the HOST collection

Latest response

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

Thank you sir. What support could not do it. You were able to help. Appreciate that very much.

This is what the response I got from Redhat.

From the case description, I can understand you are trying to extract "Server name" and "content View" information from host Collection called "PROD".

Currently, this is not available via hammer. However, you can use below API to extract the same information.

https://SATELLITE.EXAMPLE.COM/api/hosts?search=host_collection=PROD' # Replace SATELLITE.EXAMPLE.COM with your Satellite fqdn.

Feel free to get back to us if you have any concerns.

Your kind co-operation is appreciated.

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

Hello Rich,

your first option worked and just for my learning purpose. Created the "prod.csv" file. But last option the "hammer" command failed with this error below.

line 5: --search: command not found I am at 6.2.11 version.

Appreciate your help.

Regards,

MP.

There is an extra space in the command. After the \ there should be no spaces.

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.

Yes SIR indeed “Lots a ways to skin the cat”. Love this platform for redhat. I just started using this and I was using similar thing with different OS but never tried Redhat one and again I LOVE it when the answers comes from Gurus. . :)

Thank for the help, really appreciate it very much. Scott your loop I was having issue but I am able to accomplish what I needed from what I got from Will Darton and Rich.

Once again, Thanks for everyone's help.

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

You want to use a tilde ~ which means like instead of an equals sign =. Example would be

--search "host_collection ~ Prod*"

Mike,

I just tried the hammer script again on another satellite. I'm using bash for my shell. I just copy it from the screen and pasted it on the command-line it worked like a charm. Did setup ~/.hammer/cli_config.yml and defaults.yml so you don't have login manually or give it a org?

Scott

Scott,

No worries. I think and I am sure I am missing things on my end.

Appreciate your help and thanks for quick response everyone.

Regards,

MP

Close

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