| |
- compareLooseVersions(version1, version2)
- Compares two version strings using LooseVersion
Args: version1 (String) - The first version string
version2 (String) - The second version string
Returns: -1, 0, 1
-1 version1 is older than version2
0 version1 is the same as version2
1 version1 is newer than version2
Example:
thisVersion = '1.1.0-2'
thatVersion = '1.2'
if( Core.compareLooseVersions(thisVersion, thatVersion) > 0 ):
Core.updateStatus(Core.WARN, "The version is too old, update the system")
else:
Core.updateStatus(Core.IGNORE, "The version is sufficient")
- compareVersions(version1, version2)
- Compares the left most significant version string elements
Args: version1 (String) - The first version string
version2 (String) - The second version string
Returns: -1, 0, 1
-1 version1 is older than version2
0 version1 is the same as version2
1 version1 is newer than version2
Example:
thisVersion = '1.1.0-2'
thatVersion = '1.2'
if( compareVersions(thisVersion, thatVersion) > 0 ):
Core.updateStatus(Core.WARN, "The version is too old, update the system")
else:
Core.updateStatus(Core.IGNORE, "The version is sufficient")
- getExactSection(FILE_OPEN, SECTION, CONTENT)
- Extracts the first section of a supportconfig file matching SECTION and puts it into the CONTENT list, one line per list element.
NOTE: getExactSection differs from getSection in that CONTENT is a list instead of a dictionary and the SECTION string must match exactly to the Section name in the file.
Args: FILE_OPEN (String) - The supportconfig filename to open
SECTION (String) - The section regex identifier in the file
CONTENT (List) - Section contents line-by-line
Returns: True or False
True - The specified section was found
False - The section was not found
Example:
fileOpen = "boot.txt"
section = "menu.lst"
content = []
if Core.getSection(fileOpen, section, content):
for line in content:
if "xen.gz" in line:
Core.updateStatus(Core.IGNORE, "Found Xen kernel boot option"
Core.updateStatus(Core.WARN, "Missing Xen kernel boot option")
- getRegExSection(FILE_OPEN, SECTION, CONTENT)
- Extracts the first section of a supportconfig file matching SECTION and puts it into the CONTENT list, one line per list element.
NOTE: getRegExSection differs from getSection in that CONTENT is a list instead of a dictionary.
Args: FILE_OPEN (String) - The supportconfig filename to open
SECTION (String) - The section regex identifier in the file
CONTENT (List) - Section contents line-by-line
Returns: True or False
True - The specified section was found
False - The section was not found
Example:
FILE_OPEN = "boot.txt"
SECTION = "menu.lst"
CONTENT = []
if Core.getRegExSection(FILE_OPEN, SECTION, CONTENT):
for LINE in CONTENT:
if "xen.gz" in LINE:
Core.updateStatus(Core.IGNORE, "Found Xen kernel boot option"
Core.updateStatus(Core.WARN, "Missing Xen kernel boot option")
- getRegExSectionRaw(FILE_OPEN, SECTION, CONTENT)
- Extracts the first section of a supportconfig file matching SECTION and puts it into the CONTENT list, one line per list element.
NOTE: getRegExSectionRaw differs from getRegExSection by searching commented lines in the file section. All lines are included in the search.
Args: FILE_OPEN (String) - The supportconfig filename to open
SECTION (String) - The section regex identifier in the file
CONTENT (List) - Section contents line-by-line
Returns: True or False
True - The specified section was found
False - The section was not found
Example:
FILE_OPEN = "boot.txt"
SECTION = "menu.lst"
CONTENT = []
if Core.getRegExSectionRaw(FILE_OPEN, SECTION, CONTENT):
for LINE in CONTENT:
if "xen.gz" in LINE:
Core.updateStatus(Core.IGNORE, "Found Xen kernel boot option"
Core.updateStatus(Core.WARN, "Missing Xen kernel boot option")
- getSection(FILE_OPEN, SECTION, CONTENT)
- Deprecated: Use Core.getRegExSection or Core.getExactSection instead.
Extracts the first section of a supportconfig file matching SECTION and puts it into the CONTENT dictionary, one line per list element.
Args: FILE_OPEN (String) - The supportconfig filename to open
SECTION (String) - The section regex identifier in the file
CONTENT (Dictionary) - Section contents line-by-line
Returns: True or False
True - The specified section was found
False - The section was not found
Example:
fileOpen = "boot.txt"
section = "menu.lst"
content = {}
if Core.getSection(fileOpen, section, content):
for line in content:
if "xen.gz" in content[line]:
Core.updateStatus(Core.IGNORE, "Found Xen kernel boot option"
Core.updateStatus(Core.WARN, "Missing Xen kernel boot option")
- init(CLASS, CATEGORY, COMPONENT, ID, LINK, OVER_ALL, INFO, LINKS)
- Initialize the pattern metadata variables and process the startup options.
A python pattern should initialize the metadata variables and then call
this function. Required at the beginning of the pattern.
Args: CLASS = META_CLASS
CATEGORY = META_CATEGORY
COMPONENT = META_COMPONENT
ID = PATTERN_ID
LINK = PRIMARY_LINK
OVER_ALL = OVERALL
INFO = OVERALL_INFO
LINKS = OTHER_LINKS
Returns: Updates global variables
- isFileActive(FILE_OPEN)
- listSections(FILE_OPEN, CONTENT)
- Extracts all section names from FILE_OPEN and adds them to CONTENT.
Args: FILE_OPEN (String) - The supportconfig filename to open
CONTENT (List) - Section names in FILE_OPEN
Returns: True or False
True - Sections were found in FILE_OPEN
False - No sections found in FILE_OPEN
Example:
FILE_OPEN = "ha.txt"
CONTENT = {}
if Core.listSections(FILE_OPEN, CONTENT):
for LINE in CONTENT:
if "corosync.conf" in CONTENT[LINE]:
return True
return False
- normalizeVersionString(versionString)
- Converts a version string to a list of version elements
Args: versionString
Returns: A list of version string elements
- printPatternResults()
- Prints to stdout the pattern result string. The pattern result string is case
sensitive and order dependent. This function ensures the strings is printed
correctly. Call this function when the pattern had completed its processing.
Required at the end of the pattern.
Args: None
Returns: Pattern result string to stdout
- processOptions()
- A function to handle the pattern's startup options. Currently only
-p /path/to/extracted/archive is supported. It is the only required
startup option. Required at the beginning of a pattern.
Args: None
Returns: global path to extracted archive
Example: None
- setStatus(overAll, overAllInfo)
- Manually overrides the OVERALL status and the OVERALL_INFO message string.
Regardless of the current status, this function overrides it.
Args: overAll (Integer) - Current pattern status. Acceptable values are:
Core.TEMP same as Core.STATUS_TEMPORARY
Core.PART same as Core.STATUS_PARTIAL
Core.SUCC same as Core.STATUS_SUCCESS
Core.REC same as Core.STATUS_RECCOMENDED
Core.WARN same as Core.STATUS_WARNING
Core.CRIT same as Core.STATUS_CRITICAL
Core.ERROR same as Core.STATUS_ERROR
Core.IGNORE same as Core.STATUS_IGNORE
overAllInfo (String) - Current pattern status message.
Returns: Updates global OVERALL and OVERALL_INFO as needed
Example:
Core.updateStatus(Core.WARN, "Found a condition suitable for a warning")
Core.updateStatus(Core.STATUS_CRITICAL, "Found a more severe condition, the warning is overwritten")
Core.updateStatus(Core.CRIT, "Another critical condition found, but ignored because critical is already set")
Core.setStatus(Core.SUCC, "A successful condition found, and manually set to override the previous critical condition")
- updateStatus(overAll, overAllInfo)
- Update the global pattern result string with the current pattern state. The
pattern result string is only updated if overAll is greater than its previous
value. overAll is used to update the global OVERALL status value, and
overAllInfo is used to update the global OVERALL_INFO status message. The
OVERALL_INFO string is displayed on the SCA Report.
Args: overAll (Integer) - Current pattern status. Acceptable values are:
Core.TEMP same as Core.STATUS_TEMPORARY
Core.PART same as Core.STATUS_PARTIAL
Core.SUCC same as Core.STATUS_SUCCESS
Core.REC same as Core.STATUS_RECCOMENDED
Core.WARN same as Core.STATUS_WARNING
Core.CRIT same as Core.STATUS_CRITICAL
Core.ERROR same as Core.STATUS_ERROR
Core.IGNORE same as Core.STATUS_IGNORE
overAllInfo (String) - Current pattern status message.
Returns: Updates global OVERALL and OVERALL_INFO as needed
Example:
Core.updateStatus(Core.WARN, "Found a condition suitable for a warning")
Core.updateStatus(Core.STATUS_CRITICAL, "Found a more severe condition, the warning is overwritten")
Core.updateStatus(Core.CRIT, "Another critical condition found, but ignored because critical is already set")
Core.updateStatus(Core.SUCC, "A successful condition found, but ignored because the severity is already at critical")
|