Skip to content

Instantly share code, notes, and snippets.

@oogali
Created October 29, 2012 14:30
Show Gist options
  • Select an option

  • Save oogali/3973855 to your computer and use it in GitHub Desktop.

Select an option

Save oogali/3973855 to your computer and use it in GitHub Desktop.
CentOS Advisory Parser (from September 2009, never got a chance to put this into production)
#!/usr/bin/perl
$rc = 0;
while(<STDIN>) {
chomp;
## Grab severity, CentOS version, architecture, and package name
##
## Sometimes, whitespace is missing between package name and "Update"
## e.g. CESA-2009:1335 had "opensslUpdate" instead of "openssl Update"
##
## Account for fact that mailman wraps Subject: line by not requiring "Update" at the end of line
## Also account for fact that Tru Huynh's e-mail subjects use "package - type update" format
if ($_ =~ /^Subject:\s+\[CentOS-announce\]\s+\S+\s+(\w*)\s*CentOS\s+(\d+)\s+(x86_64|i386|i686)\s+(\S+)\s*(Update$|$|\-\s*$)/) {
## Severity may be missing, replace with "Unknown" if it is
## e.g. CESA-2009:1202, CESA-2009:1165, CESA-2009:1192, CESA-2009:1191, CESA-2009:1196, CESA-2009:1214
## CESA-2009:1215, and CESA-2009:1212 had no severity in subject lines
$severity = $1;
if ($severity eq "") {
$severity = "Unknown";
}
$version = $2;
$arch = $3;
$package = $4;
if ($package =~ /(\S*)Update/) {
$package = $1;
}
}
## Don't trust CentOS advisory number in subject, has had typos in the past
## e.g. "CESA-2009:1232" e-mailed out as "CESA-2009:123"
## "CESA-2009:1165" e-mailed out as "CEBA-2009:1165"
## "CESA-2009:1192" e-mailed out as "CEBA-2009:1192"
## "CESA-2009:1191" e-mailed out as "CEBA-2009:1191"
## "CESA-2009:1196" e-mailed out as "CEBA-2009:1196"
## "CESA-2009:1202" e-mailed out as "CEBA-2009:1202"
## "CESA-2009:1212" e-mailed out as "CEBA-2009:1212"
## "CESA-2009:1214" e-mailed out as "CEEA-2009:1214"
##
## Do minimal matching of RHN URL, has had typos in the past
## e.g. CESA-2009:1212 had URI of "RHBA-2009-1212.html" instead of "RHSA-2009-1212.html"
if ($_ =~ /(\d+)-(\d+)\.html/) {
$advisory = sprintf("%04d-%d", $1, $2);
}
if ($_ =~ /\s*(.*)\.rpm/) {
$rpm = $1;
## extra chopping: Karanbir Singh's e-mails carry MD5 hashes (which shouldn't be used)
if ($rpm =~ /\s+(.*)/) {
$rpm = $1;
}
## extra chopping: Tru Huynh's e-mails carry relative paths, grab the last part of filename
if ($rpm =~ /\//) {
@rp = split("\/", $rpm);
$rpm = $rp[$#rp];
}
$rpmfiles[$rc++] = sprintf("%s.rpm", $rpm);
}
}
## Normalize our output and print
printf("CentOS %d/%s Advisory (CESA:%s)\n", $version, $arch, $advisory);
printf("Package: %s\n", $package);
printf("Severity: %s\n", $severity);
printf("\nFiles Updated in CentOS %d/%s Repository:\n", $version, $arch);
foreach $file (@rpmfiles) {
printf("\t%s\n", $file);
}
printf("\nFor more information, please see https://rhn.redhat.com/errata/RHSA-%s.html\n", $advisory);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment