SDP::Core - The Support Diagnostic Pattern core perl library
use SDP::Core;
Provides necessary fuctions to have a support pattern interact correctly with the NSA client.
This is the initial overall status. Used for pre-condition processing.
All criteria are only partially checked. A status that can be used to test various conditional before assigning a valid exit condition, which is an overall status of STATUS_SUCCESS or higher. Used for pre-condition processing.
All criteria have been checked. All are confirmed to be valid and working.
All criteria have been checked. However, the linked solution is a recommendation and does not fall into the other categories. Used to recommend an optimization TID or documentation, or even product promotions.
All criteria have been checked. This status is used to suggest a SUSE product or service from which the customer may benefit.
All criteria have been checked. The criteria show a problem may occur, but may not currently be causing symptoms.
All criteria have been checked. The critiera show the server is currently matching criteria for the issue being checked.
Not all criteria could be checked. A fatal pattern error has occurred, like a file not found.
The array returned by each pattern. There are mandatory fields and optional KEY=VALUE pairs that match criteria checked. Use SDP::Core::printPatternResults to return the results to the NSA client.
Set with the -p startup option. This is the directory where the archive is located. Default: Current Working Directory
Sets the log level for pattern output. The -d startup option sets $OPT_LOGLEVEL to LOGLEVEL_DEBUG. (LOGLEVEL_QUIET|LOGLEVEL_DEBUG) Default: LOGLEVEL_QUIET
Keeps track of the overall status. The worst case of all criteria checked is saved in $GSTATUS, which is returned in @PATTERN_RESULTS as the OVERALL status. You should never have to set this manually, SDP::Core::setStatus and SDP::Core::updateStatus to that.
Processes the pattern's startup options, which includes setting $ARCH_PATH.
SDP::Core::processOptions();
None
None
Initializes the OVERALL and OVERALL_INFO to the set status.
SDP::Core::setStatus(STATUS, $description);
STATUS (STATUS_TEMPORARY|STATUS_PARTIAL|STATUS_SUCCESS|STATUS_RECOMMEND|STATUS_PROMOTION|STATUS_WARNING|STATUS_CRITICAL|STATUS_ERROR)
$description (Brief description string)
None
Updates the OVERALL status if status is more severe that before. It also adds the specified key=value pair to @PATTERN_RESULTS. If the OVERALL status is green, and updateStatus is called with STATUS_SUCCESS, the OVERALL_INFO will not be updated, because the status is not worse that it was before. Use setStatus to update OVERALL and OVERALL_INFO in this case. A status greater than or equal to STATUS_ERROR, will trigger a script exit after printing @PATTERN_RESULTS.
SDP::Core::updateStatus(STATUS, $value);
STATUS (STATUS_TEMPORARY|STATUS_PARTIAL|STATUS_SUCCESS|STATUS_RECOMMEND|STATUS_PROMOTION|STATUS_WARNING|STATUS_CRITICAL|STATUS_ERROR)
None
Prints @PATTERN_RESULTS to STDOUT
SDP::Core::printPatternResults();
None
None
None
Converts the $YEAR, $MONTH, $DAY date elements to the number of days since 1970 Jan 01.
my $DAYS = SDP::Core::convertDate2Days(2009, 'Jan', 2); SDP::Core::updateStatus(STATUS_PARTITAL, "Number of days from 1970 Jan 01 to 2009 Jan 02: $DAYS");
$YEAR (Use all four digits)
$MONTH (Use locale's abbreviated month name {e.g., Jan})
$DAY (Use the day of month {e.g, 01})
Number of days since 1970 Jan 01.
None
Returns true if the $FILE_NAME is in the supportconfig archive.
my $FILE_NAME = 'plugin-iPrint.txt'; if ( SDP::Core::fileInArchive($FILE_NAME) ) { SDP::Core::update_state(STATUS_SUCCESS, 'FILE', "File Found: $FILE_NAME"); } else { SDP::Core::update_state(STATUS_WARNING, 'FILE', "File NOT Found: $FILE_NAME"); }
$FILE_NAME (The file to test.)
0 = File NOT found in archive
1 = File found in archive
None
Converts the $INPUT_STRING to bytes
my $INPUT_STRING = "2.5G"; my $BYTES = SDP::Core::convert2bytes($INPUT_STRING); SDP::Core::updateStatus(STATUS_PARTIAL, "$INPUT_STRING converts to $BYTES bytes");
$INPUT_STRING (A digit or decimal followed by a case insensitive type qualifer.)
Valid type modifier:
k = Kilobytes m = Megabytes (Default if no qualifier specified) g = Gigbytes t = Terabytes p = Petabytes
Number of bytes converted from $INPUT_STRING
-1 for invalid type modifiers
None
Removes leading and trailing white space from $STRING, ltrimWhite trims the left and rtrimWhite the right.
my $STRING = " This is a test \t "; SDP::Core::updateStatus(STATUS_PARTIAL, SDP::Core::trimWhite($STRING)); SDP::Core::updateStatus(STATUS_PARTIAL, SDP::Core::ltrimWhite($STRING)); SDP::Core::updateStatus(STATUS_PARTIAL, SDP::Core::rtrimWhite($STRING));
$STRING (A string)
String without leading or trailing whitespace.
None
Stores the section names in ARRAY_POINTER contined in FILE_OPEN.
my $FILE_OPEN = 'fs-diskio.txt'; my @FILE_SECTIONS = (); my $SECTION = '';
if ( SDP::Core::listSections($FILE_OPEN, \@FILE_SECTIONS) ) { foreach $SECTION (@FILE_SECTIONS) { if ( $SECTION =~ m/\/parted -s / ) { printf("Section with parted: $SECTION\n"); } } } else { SDP::Core::updateStatus(STATUS_ERROR, "ERROR: myFunction(): No sections found in $FILE_OPEN"); }
FILE_OPEN (The supportconfig FILE_OPEN to look in)
ARRAY_POINTER (A pointer to an array that will contain the FILE_OPEN section names)
Number of elements in the array
None
Opens FILE_OPEN and looks for SEARCH_STRING anywhere in the file
my $FILE_OPEN = 'modules.txt'; my $MODULE = 'usbcore'; my $SEARCH_STRING = "options.*$MODULE.*usbfs_snoop" my $FOUND = SDP::Core::inSection($FILE_OPEN, $SEARCH_STRING); if ( $FOUND ) { SDP::Core::updateStatus(STATUS_SUCCESS, "Found $SEARCH_STRING in $FILE_OPEN, section $FOUND"); } else { SDP::Core::updateStatus(STATUS_WARNING, "NOT FOUND: $SEARCH_STRING in $FILE_OPEN"); }
FILE_OPEN (The supportconfig filename to look in)
SEARCH_STRING (The string you are looking for in FILE_OPEN)
The section name in $FILE_OPEN where $SEARCH_STRING is first found.
None
Loads the entire $FILE_OPEN into @CONTENT, skipping blank lines.
my $FILE_OPEN = 'modules.txt'; my @CONTENT = (); my $STATE = 0; my $CONTENT_FOUND = 0; if ( SDP::Core::loadFile($FILE_OPEN, \@CONTENT) ) { foreach $_ (@CONTENT) { next if ( m/^\s*$/ ); # Skip blank lines if ( $STATE ) { if ( /^#==\[/ ) { $STATE = 0; SDP::Core::printDebug(" main DONE", "State Off"); } elsif ( /SearchForSectionContent/ ) { # Section content needed $CONTENT_FOUND = 1; } } elsif ( /^# SectionNameToSearchFor/ ) { # Section $STATE = 1; SDP::Core::printDebug(" main CHECK", "Section: $_"); } } } else { SDP::Core::updateStatus(STATUS_ERROR, "ERROR: checkSomething(): Cannot load file: $FILE_OPEN"); }
LOAD_FILE (The supportconfig filename to open)
ARRAY_REF (An address to an array)
$ARRAY_REF and the number lines in the array
None
Opens file_name and retrieves the section matching the search string into the specified array
SDP::Core::getSection($file_name, $section, \@array_pointer);
file_name (The supportconfig file_name to look in)
section (The name of the section you want)
array_pointer (A pointer to an array that will contain the lines of the section asked for)
Number of elements in the array
None
Converts a version string $VERSTR to an array of version elements. This function separates elements based on /usr/share/doc/packages/rpm/manual/dependencies. See the paragraph beginning: "The algorithm that RPM uses to determine the version...."
my $VERSTR = '1.0-1.83'; my @FIRST = SDP::Core::normalizeVersionString($VERSTR); SDP::Core::printDebug('$FIRST[$#FIRST]', "$FIRST[$#FIRST]");
$VERSTR (A version string)
Array of version elements
None
Compares two version strings. Only the most significant version components are compared. For example, if 2.6.5 is compared with 2.6.16.60-0.23, then only 2.6.5 and 2.6.16 will be used for the comparison. Characters in the version strings are separated into their own version element, as if there were a "." at the beginning and end of the group of letters. String comparisons are used on string elements and numeric comparisons are used for digits. If a numeric element is compared to a string element, the numeric element will be converted to string for the comparison.
SDP::Core::compareVersions($verstr1, $verstr2);
$verstr1 (The first version string to compare)
$verstr2 (The last version string to compare)
-1 if $verstr1 < $verstr2
0 if $verstr1 == $verstr2
1 if $verstr1 > $verstr2
None
Prints the label and value to STDOUT if the $OPT_LOGLEVEL is set to LOGLEVEL_DEBUG or higher.
SDP::Core::printDebug($label, $value);
$label (Any string that labels you debug output)
$value (The values or variables you want to print out. Does not support arrays or hashes.)
None
None
Jason Record <jason.record@suse.com>
Copyright (C) 2008-2021 SUSE LLC
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.