email report for critical systems

Latest response

Hi

Would love to have a report that would email weekly that listed the outstanding errata and also which servers they needed installing on.

Can this be done out of the box ? or is a script needed ?

thanks

Responses

I will do more looking for an answer (as this is a good question). There are a number of canned jobs that exist from the base-install. You have to login as the Satellite Administrator account and click Admin in the top menu area - the click on Task Schedules.
errata-cache-default belongs to the errata-cache-bunch, which has 2 jobs (errata-mailer and errata-cache) - which are managed/executed by the taskomatic component. I do not how how these jobs are created or managed, however :-(

This all works out of the box? Just go to the Administration account (or any really). Preferences and check off receive email notifications. You can further enable/disable which notifications you or other users receive.

Thanks for the reply david but i am looking for an email option showing an overview of the servers that have outstanding errata.

Paul,

I had to write one myself using the API using my kindergarten-level Python skills, as the System Currency report via the WebUI (https://satellite.yourcompany.org/rhn/systems/SystemCurrency.do) doesn't e-mail. Would be nice if this could be scheduled via the RHN Satellite Schedules (https://satellite.yourcompany.org/rhn/admin/SatSchedules.do) pages along with target e-mail addresses. This would be a really useful addition to Satellite 5.X.

I also ended up focusing only on the outstanding Security Errata rather than bugfixes & enhancements and ranked systems by the oldest Critical, Important, Moderate and Low Security Errata.

The big downside is that Errata only show as outstanding for a system if the Errata have been cloned into the channel to which the system is subscribed. The way I've set up our environments (Dev>Test>UAT>Staging>Prod), I shouldn't clone Errata into Prod until they've been cloned, applied, tested and approved through each of the other environments. I don't know how to get round this problem yet, other than cloning all the way through the channels regularly and trusting that Errata are applied to systems in the right order rather than straight into Prod.

Happy to share code. As long as nobody laughs :-) It's the first Python I've attempted - and it shows! Is there a community code repository anywhere?

D

Hello,

Please, can you share your script ?

Many thanks for the work

Matthias

looks like with satellite 5.6, the new spacewalk-report system-currency might do the trick. Shows the current outstanding per server.

spacecmd is an extremely helpful command. I (like Duncan) am not well-versed in Python, or the API - and I could not figure out how to set a "threshold" for errata (i.e. only report on systems that have "critical errata"). But, this is something I put together to generate ALL errata for ALL my systems and it's pretty straight-forward.

#!/bin/bash
USER='<removed>'
PASS='<removed>'
SPACECMD="/usr/bin/spacecmd -q -u $USER -p $PASS"

for HOST in `$SPACECMD system_list`
do  
  echo "#  *  *  *  *  *  *  *  *  *  *  *  *  *"
  echo ""
  echo "# $HOST "
  $SPACECMD system_listerrata $HOST  
  echo ""
  echo "#  *  *  *  *  *  *  *  *  *  *  *  *  *"
done

exit 0

I'll make my self for satellite 6 errata report for one organisation
Perhaps someone want use it

Regards

#!/bin/bash

# MAPPING
USER="admin"
PASSWORD="CHANGE-ME"
MAIL_TO="my-mail@my-domain.com"
ORGANISATION_ID="4"
SATELLITE_URL="https://${USER}:${PASSWORD}@my-satellite-hostname"
SYSTEM_URI="/katello/api/v2/organizations/${ORGANISATION_ID}/systems/report"


# RECUPERATION DE LA LISTE DE SYSTEM / GETTING SYSTEM LIST
UUID_LIST=$(curl -s --insecure ${SATELLITE_URL}${SYSTEM_URI} | sed '/\(.*\)---\(.*\)/d' |grep -v "uuid" | awk '{print $4}')
COUNT=$(curl -s --insecure ${SATELLITE_URL}${SYSTEM_URI} | sed '/\(.*\)---\(.*\)/d' |grep -v "uuid" | wc -l)
NUMBER_OF_SYS=${COUNT}
while [[ ${COUNT} -gt "0" ]]
        do
                LIGNE=$(curl -s --insecure ${SATELLITE_URL}${SYSTEM_URI} | sed '/\(.*\)---\(.*\)/d' |grep -v "uuid" | sed -n ${COUNT}p)
                NAME[${COUNT}]=$(echo ${LIGNE} | awk '{print $2}')
                UUID[${COUNT}]=$(echo ${LIGNE} | awk '{print $4}')
                COUNT=$((${COUNT} - 1))
        done

# REMISE A 0 DU COMPTEUR / SETTING COUNT TO 0
COUNT=${NUMBER_OF_SYS}

# ENVOIS DES MAILS REPORT / MAIL REPORT
while [[ ${COUNT} -gt "0" ]]
        do
                SYSTEM_CONTENT=$(curl -s --insecure ${SATELLITE_URL}/katello/api/v2/systems/${UUID[${COUNT}]}/errata  | grep "errata_id" | wc -l)
                # VERIFDICATION QU'IL Y A BIEN DES ERRATA
                if [[ ${SYSTEM_CONTENT} -gt "0" ]]
                        then
                                HEADER="title,version,description,status,id,errata_id,reboot_suggested,updated,issued,release,solution,applicable_consumers,type,packages"
                                MAIL_CONTENT=$(curl -s --insecure ${SATELLITE_URL}/katello/api/v2/systems/${UUID[${COUNT}]}/errata  | sed 's/"//g' | sed "s/{/\n/g" | sed "s/},$//" | sed -e '2d' -e '3d' | sed 's/}]}$//' | sed 's/\([[:alnum:]_]*\)://g')
                                echo -e "${HEADER}\n${MAIL_CONTENT}" | mailx -s "Errata for ${NAME[${COUNT}]}" ${MAIL_TO}
                fi
                COUNT=$((${COUNT} - 1))

        done

Thanks Matthias - I'm still a bash-guy and I wish there were more examples out there still for folks to get an idea of how to use bash constructively (myself include ;-)

Could you add a small example of the expected output as well?

For each system in the organisation, an email was send with this content like:

title,version,description,status,id,errata_id,reboot_suggested,updated,issued,release,solution,applicable_consumers,type,packages
 java-1.7.0-openjdk security and bug fix update,null,null,null,2ce0445d-a9c0-4152-9067-53e7499556c7,RHSA-1620,null,null,2014-10-15,null,null,[],security,[]
libcgroup bug fix update,null,null,null,d1061ba8-879f-461c-9025-35bb4fb9c47b,RHBA-1640,null,null,2014-10-15,null,null,[],bugfix,[]
policycoreutils bug fix update,null,null,null,6365c1d6-649d-4f44-942c-10c1b05e4d3b,RHBA-1625,null,null,2014-10-14,null,null,[],bugfix,[]

I thinks is not difficult to export it in html or something like ;)

Regards

Thanks for sharing it, Matthias

new version for sending a html email report

#!/bin/bash
## Need jq in the PATH like /usr/bin (http://stedolan.github.io/jq/)
## Need sendmail

# MAPPING
USER="admin"
PASSWORD="CHANGE-ME"
MAIL_TO="my-mail@my-domain.com"
ORGANISATION_ID="4"
SATELLITE_URL="https://${USER}:${PASSWORD}@my-satellite-hostname"
SYSTEM_URI="/katello/api/v2/organizations/${ORGANISATION_ID}/systems/report"

COMPANY_NAME="NAME_OF_COMPANY"
COMPANY_URL="http://WEBSITE_OF_COMPANY"
TOP_LOGO_URL="http://WEBSITE_OF_COMPANY/logos/logo.gif" # URL FOR HEADER LOGO
BOTTOM_LOGO_URL="http://WEBSITE_OF_COMPANY/logos/logo-footer.gif" # URL FOR FOOTER LOGO


# RECUPERATION DE LA LISTE DE SYSTEM / GENERATING SYSTEM LIST
UUID_LIST=$(curl -s --insecure ${SATELLITE_URL}${SYSTEM_URI} | sed '/\(.*\)---\(.*\)/d' |grep -v "uuid" | awk '{print $4}')
COUNT=$(curl -s --insecure ${SATELLITE_URL}${SYSTEM_URI} | sed '/\(.*\)---\(.*\)/d' |grep -v "uuid" | wc -l)
NUMBER_OF_SYS=${COUNT}
while [[ ${COUNT} -gt "0" ]]
    do
        LIGNE=$(curl -s --insecure ${SATELLITE_URL}${SYSTEM_URI} | sed '/\(.*\)---\(.*\)/d' |grep -v "uuid" | sed -n ${COUNT}p)
        NAME[${COUNT}]=$(echo ${LIGNE} | awk '{print $2}')
        UUID[${COUNT}]=$(echo ${LIGNE} | awk '{print $4}')
        COUNT=$((${COUNT} - 1))
    done

# REMISE A 0 DU COMPTEUR | DEFINE COUNT TO 0
COUNT=${NUMBER_OF_SYS}

# ENVOIS DES MAILS REPORT | GENERATING AND SENDING EMAIL REPORT
while [[ ${COUNT} -gt "0" ]]
    do
        SYSTEM_CONTENT=$(curl -s --insecure ${SATELLITE_URL}/katello/api/v2/systems/${UUID[${COUNT}]}/errata  | grep "errata_id" | wc -l)
        # VERIFDICATION QU'IL Y A BIEN DES ERRATA | VERIFYING IF THERE IS ERRATA
        if [[ ${SYSTEM_CONTENT} -gt "0" ]]
            then
                # GENERATING HTML REPORT | GENERATING REPORT
                HTML_REPORT="/tmp/${NAME[${COUNT}]}.html"
                ERRATA_ID_LIST=$(curl -s --insecure ${SATELLITE_URL}/katello/api/v2/systems/${UUID[${COUNT}]}/errata  | jq '.results[].errata_id' | sed 's/"//g')
                ERRATA_COUNT=0
                for ERRATA in $(echo ${ERRATA_ID_LIST})
                    do
                        CURL_CONTENT=$(curl -s --insecure ${SATELLITE_URL}/katello/api/v2/systems/${UUID[${COUNT}]}/errata/${ERRATA})
                        MAIL_CONTENT_TITLE[${ERRATA_COUNT}]=$(echo ${CURL_CONTENT} | jq '.title' | sed 's/"//g')
                        MAIL_CONTENT_VERSION[${ERRATA_COUNT}]=$(echo ${CURL_CONTENT} | jq '.version' | sed 's/"//g')
                        #MAIL_CONTENT_DESCRIPTION[${ERRATA_COUNT}]=$(echo ${CURL_CONTENT} | jq '.description' | sed 's/"//g')
                        MAIL_CONTENT_STATUS[${ERRATA_COUNT}]=$(echo ${CURL_CONTENT} | jq '.status' | sed 's/"//g')
                        #MAIL_CONTENT_ID[${ERRATA_COUNT}]=$(echo ${CURL_CONTENT} | jq '.id' | sed 's/"//g')
                        MAIL_CONTENT_ERRATA_ID[${ERRATA_COUNT}]=$(echo ${CURL_CONTENT} | jq '.errata_id' | sed 's/"//g')
                        MAIL_CONTENT_REBOOT[${ERRATA_COUNT}]=$(echo ${CURL_CONTENT} | jq '.reboot_suggested' | sed 's/"//g')
                        MAIL_CONTENT_UPDATED[${ERRATA_COUNT}]=$(echo ${CURL_CONTENT} | jq '.updated' | sed 's/"//g')
                        MAIL_CONTENT_ISSUED[${ERRATA_COUNT}]=$(echo ${CURL_CONTENT} | jq '.issued' | sed 's/"//g')
                        #MAIL_CONTENT_RELEASE[${ERRATA_COUNT}]=$(echo ${CURL_CONTENT} | jq '.release' | sed 's/"//g')
                        #MAIL_CONTENT_SOLUTION[${ERRATA_COUNT}]=$(echo ${CURL_CONTENT} | jq '.solution' | sed 's/"//g')
                        #MAIL_CONTENT_APPLICABLE[${ERRATA_COUNT}]=$(echo ${CURL_CONTENT} | jq '.applicable_consumers' | sed 's/"//g')
                        MAIL_CONTENT_TYPE[${ERRATA_COUNT}]=$(echo ${CURL_CONTENT} | jq '.type' | sed 's/"//g')
                        MAIL_CONTENT_PACKAGES[${ERRATA_COUNT}]=$(echo ${CURL_CONTENT} | jq '.packages' | sed 's/"//g' | sed 's/\[//' | sed 's/\]//' | sed 's/,/<br \/>/g')
                        MAIL_CONTENT[${ERRATA_COUNT}]="<tr><td>${MAIL_CONTENT_TITLE[${ERRATA_COUNT}]}</td><td>${MAIL_CONTENT_VERSION[${ERRATA_COUNT}]}</td><td>${MAIL_CONTENT_STATUS[${ERRATA_COUNT}]}</td><td><a href=http://access.redhat.com/errata/${MAIL_CONTENT_ERRATA_ID[${ERRATA_COUNT}]}>${MAIL_CONTENT_ERRATA_ID[${ERRATA_COUNT}]}</a></td><td>${MAIL_CONTENT_REBOOT[${ERRATA_COUNT}]}</td><td>${MAIL_CONTENT_UPDATED[${ERRATA_COUNT}]}</td><td>${MAIL_CONTENT_ISSUED[${ERRATA_COUNT}]}</td><td>${MAIL_CONTENT_TYPE[${ERRATA_COUNT}]}</td><td width=350>${MAIL_CONTENT_PACKAGES[${ERRATA_COUNT}]}</td></tr>"
                        ERRATA_COUNT=$((${ERRATA_COUNT} + 1 ))
                    done
                ARRAY[${UUID}${COUNT}]=$(echo -e "${MAIL_CONTENT[*]}")
                # ENVOIS DE L'EMAIL | SENDING REPORT
                echo -e "
<html>
    <head>
        <style type=\"text/css\">
            <!--
            #tab, #tab caption
            {
                margin: auto;
            }

            #tab
            {
                border: #DDEEFF 2px solid;
                border-collapse: separate;
                border-spacing: 2px;
                empty-cells: hide;
                table-layout: fixed;
                width: 1600px;
            }

            #tab caption
            {
                background-color: #DDEEFF;
                font-size: 0.8em;
            }

            #tab th
            {
                color: #996600;
                background-color: #DEDEDE;
                border: #DDEEFF 1px solid;
                font-variant: small-caps;
                font-size: 0.8em;
                letter-spacing: 1px;
                height: 50px;
            }

            #tab td
            {
                border: #DDEEFF 1px solid;
                padding-left: 10px;
                width: 150px; 
                height: 50px;
                overflow: ellipsis;
            }

            #navcol
            {
                width: 200px;
                background-color: #DDEEFF;
                background-color: #F4FAFD;

            }

            #numcol
            {
                width: 150px;
            }

            #tab tfoot
            {
                font-size: 0.7em;
                background-color: #FFCC66;
                color: #996600;
                letter-spacing: 1px;
            }
            -->
        </style>
    </head>
    <div align=\"center\">
        <a href=\"${COMPANY_URL}\">
            <img src=\"${TOP_LOGO_URL}\" alt=\"${COMPANY_NAME}\">
        </a>
        <br />
        <br />
        <br />
        <br />
        <table cellpadding=\"0\" cellspacing=\"0\" id=\"tab\" >
            <tr><th>title</th><th>version</th><th>status</th><th>id</th><th>reboot_suggested</th><th>updated</th><th>issued</th><th>type</th><th width=350>packages</th></tr>
            ${ARRAY[*]}
        </table>
        <br />
        <br />
        <br />
        <br />
        <div align=\"right\">
                <div>
                <img src=\"${BOTTOM_LOGO_URL}\" alt=\"\">
            </div>
            <div>
                2014 ${COMPANY_NAME}. All rights reserved.
            </div>
        </div>
    </div>
</html>
" > ${HTML_REPORT}


            # SEND THE EMAIL
            (
                    echo "From: ${MAIL_FROM}"
                    echo "To: ${MAIL_TO}"
                    echo "subject: Updates available for the system ${NAME[${COUNT}]}"
                    echo "MIME-Version: 1.0"
                    echo "Content-Type: text/html"
                    echo "Content-Disposition: inline"
                    cat ${HTML_REPORT}
            ) | /usr/sbin/sendmail -v ${MAIL_TO}
            rm -f ${HTML_REPORT}
        fi
        COUNT=$((${COUNT} - 1))
    done