NAME

SDP::Core - The Support Diagnostic Pattern core perl library


SYNOPSIS

use SDP::Core;


DESCRIPTION

Provides necessary fuctions to have a support pattern interact correctly with the NSA client.


CONSTANTS

Setting Severity Status

STATUS_TEMPORARY

This is the initial overall status. Used for pre-condition processing.

STATUS_PARTIAL

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.

STATUS_SUCCESS

All criteria have been checked. All are confirmed to be valid and working.

STATUS_RECOMMEND

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.

STATUS_PROMOTION

All criteria have been checked. This status is used to suggest a Novell product or service from which the customer may benefit.

STATUS_WARNING

All criteria have been checked. The criteria show a problem may occur, but may not currently be causing symptoms.

STATUS_CRITICAL

All criteria have been checked. The critiera show the server is currently matching criteria for the issue being checked.

STATUS_ERROR

Not all criteria could be checked. A fatal pattern error has occurred, like a file not found.

Setting Log Levels

LOGLEVEL_QUIET
LOGLEVEL_DEBUG


GLOBAL VARIABLES

@PATTERN_RESULTS

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.

$ARCH_PATH

Set with the -p startup option. This is the directory where the archive is located. Default: Current Working Directory

$OPT_LOGLEVEL

Sets the log level for pattern output. The -d startup option sets $OPT_LOGLEVEL to LOGLEVEL_DEBUG. (LOGLEVEL_QUIET|LOGLEVEL_DEBUG) Default: LOGLEVEL_QUIET

$GSTATUS

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.


FUNCTIONS: NSA Client Integration


processOptions

Description

Processes the pattern's startup options, which includes setting $ARCH_PATH.

Usage

SDP::Core::processOptions();

Input

None

Output

$ARCH_PATH, $OPT_LOGLEVEL

Requires

None


setStatus

Description

Initializes the OVERALL and OVERALL_INFO to the set status.

Usage

SDP::Core::setStatus(STATUS, $description);

Input

STATUS (STATUS_TEMPORARY|STATUS_PARTIAL|STATUS_SUCCESS|STATUS_RECOMMEND|STATUS_PROMOTION|STATUS_WARNING|STATUS_CRITICAL|STATUS_ERROR)

$description (Brief description string)

Output

@PATTERN_RESULTS, $GSTATUS

Requires

None


updateStatus

Description

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.

Usage

SDP::Core::updateStatus(STATUS, $value);

Input

STATUS (STATUS_TEMPORARY|STATUS_PARTIAL|STATUS_SUCCESS|STATUS_RECOMMEND|STATUS_PROMOTION|STATUS_WARNING|STATUS_CRITICAL|STATUS_ERROR)

Output

@PATTERN_RESULTS, $GSTATUS

Requires

None


printPatternResults

Description

Prints @PATTERN_RESULTS to STDOUT

Usage

SDP::Core::printPatternResults();

Input

None

Output

None

Requires

None


FUNCTIONS: Base



convertDate2Days

Description

Converts the $YEAR, $MONTH, $DAY date elements to the number of days since 1970 Jan 01.

Usage
        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");
Input

$YEAR (Use all four digits)

$MONTH (Use locale's abbreviated month name {e.g., Jan})

$DAY (Use the day of month {e.g, 01})

Output

Number of days since 1970 Jan 01.

Requires

None



fileInArchive

Description

Returns true if the $FILE_NAME is in the supportconfig archive.

Usage
        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");
        }
Input

$FILE_NAME (The file to test.)

Output

0 = File NOT found in archive

1 = File found in archive

Requires

None


convertDate2Days

Description

Converts the $INPUT_STRING to bytes

Usage
        my $INPUT_STRING = "2.5G";
        my $BYTES = SDP::Core::convert2bytes($INPUT_STRING);
        SDP::Core::updateStatus(STATUS_PARTIAL, "$INPUT_STRING converts to $BYTES bytes");
Input

$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
Output

Number of bytes converted from $INPUT_STRING

-1 for invalid type modifiers

Requires

None


trimWhite, ltrimWhite, rtrimWhite

Description

Removes leading and trailing white space from $STRING, ltrimWhite trims the left and rtrimWhite the right.

Usage
        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));
Input

$STRING (A string)

Output

String without leading or trailing whitespace.

Requires

None


FUNCTIONS: Information Gathering


listSections

Description

Stores the section names in ARRAY_POINTER contined in FILE_OPEN.

Usage
        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");
        }
Input

FILE_OPEN (The supportconfig FILE_OPEN to look in)

ARRAY_POINTER (A pointer to an array that will contain the FILE_OPEN section names)

Output

Number of elements in the array

Requires

None


inSection

Description

Opens FILE_OPEN and looks for SEARCH_STRING anywhere in the file

Usage
        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");
        }
Input

FILE_OPEN (The supportconfig filename to look in)

SEARCH_STRING (The string you are looking for in FILE_OPEN)

Output

The section name in $FILE_OPEN where $SEARCH_STRING is first found.

Requires

None


loadFile

Description

Loads the entire $FILE_OPEN into @CONTENT, skipping blank lines.

Usage
        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");
        }
Input

LOAD_FILE (The supportconfig filename to open)

ARRAY_REF (An address to an array)

Output

$ARRAY_REF and the number lines in the array

Requires

None


getSection

Description

Opens file_name and retrieves the section matching the search string into the specified array

Usage

SDP::Core::getSection($file_name, $section, \@array_pointer);

Input

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)

Output

Number of elements in the array

Requires

None


normalizeVersionString

Description

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...."

Usage
        my $VERSTR = '1.0-1.83';
        my @FIRST = SDP::Core::normalizeVersionString($VERSTR);
        SDP::Core::printDebug('$FIRST[$#FIRST]', "$FIRST[$#FIRST]");
Input

$VERSTR (A version string)

Output

Array of version elements

Requires

None


FUNCTIONS: Comparisons


compareVersions

Description

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.

Usage

SDP::Core::compareVersions($verstr1, $verstr2);

Input

$verstr1 (The first version string to compare)

$verstr2 (The last version string to compare)

Output

-1 if $verstr1 < $verstr2

0 if $verstr1 == $verstr2

1 if $verstr1 > $verstr2

Requires

None


FUNCTIONS: Debugging


printDebug

Description

Prints the label and value to STDOUT if the $OPT_LOGLEVEL is set to LOGLEVEL_DEBUG or higher.

Usage

SDP::Core::printDebug($label, $value);

Input

$label (Any string that labels you debug output)

$value (The values or variables you want to print out. Does not support arrays or hashes.)

Output

None

Requires

None


CONTRIBUTORS

Jason Record <jrecord@novell.com>

Douglas Kimball <dkimball@novell.com>

Tregaron Bayly <tbayly@novell.com>


COPYRIGHT

Copyright (C) 2008,2009,2010 Novell, Inc.

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/>.