Announcement

Collapse
No announcement yet.

Qsysopr messages needs to return ok, warning or critical Help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Ritchie_
    replied
    Always happy to find and try script (perl or java) in order to see if that can improve our monitoring.. so.. if you can share.. would be great :-)
    thanks so far.. will check above script

    Leave a comment:


  • BigFredi
    replied
    There you go, I found it deep into my src directory.

    2 things to notice...
    1. I was basically learning perl at the time, some of the things I've seen in this code, caused me horror.
    2. This is one of those… when I wrote it, only god and me knew what we were doing, now only god does.


    Last but not least, at the time, I planned to have a script with multiple checks on it (the check parameter would indicate which one to run). I've found also the copies that run the other checks, but apparently I never consolidated it in a single script. I could append tomorrow the differences in code, and you can try to patch them together into a single script, should be no big deal, although as I say, I lost interest and moved myself to a java code (if you think that perl code is horrible, you should see the frankenstein I created in java) that retrieves the data from the iSeries scheduled from cron and then some perl scripts parse the info to retrieve the particular info. I could share that also.

    PHP Code:
    #! /usr/bin/perl
    #
    # check_as400 plugin for Nagios
    #
    # usage:
    #    check_as400 host service
    #
    # initial version: 22 May 2009 by Alfredo Garcia
    # current status: $Revision: 0.01 $
    #
    # Copyright Notice: GPL
    #

    use Net::Telnet ();
    use 
    Nagios::Plugin ();


    $DEBUG=0;
    $username="your_username";
    $password="your_password";
    $qcmd_screen=0;
    $login_screen_ok=0;
    $login_screen_failed=0;
    $MAX_LOGIN_ATTEMPS=3;

    sub telnetError {

            
    my $ERR $_[0];

            if (
    $DEBUG) {print "Telnet error: $ERR\n"}
            
    $login_screen_failed $login_screen_failed 1;
            return;

    }

    sub logout {

            
    sleep (2);
    }

    $t = new Net::Telnet (Timeout => 20);
    if (
    $DEBUG) {$t->dump_log("./debug_dump.log")};
    if (
    $DEBUG) {$t->input_log("./debug_in.log")};

    $plugin Nagios::Plugin->new(
       
    usage => "Usage: %s [ -v|--verbose ]  [-H <host>] [-C|--Check [ASP|DB|JOBS|AJ|MSGQ]] [-t <timeout>] "
        
    "[ -c|--critical=<threshold> ] [ -w|--warning=<threshold> ]",
                    
    version => $VERSION,
     
    #               blurb   => $blurb,
     #               extra   => $extra,
     #               url     => $url,
     #               license => $license,
    #                plugin  => basename $0,
                    
    timeout => 15

    );

    # add valid command line options and build them into your usage/help documentation.

            
    $plugin->add_arg(
                    
    spec => 'warning|w=s',
                    
    help => '-w, --warning=INTEGER:INTEGER .  See '
                            
    'http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT '
                            
    'for the threshold format. ',
                    default => 
    3000,
                    
    required => 1
            
    );

            
    $plugin->add_arg(
                    
    spec => 'critical|c=s',
                    
    help => '-c, --critical=INTEGER:INTEGER .  See '
                            
    'http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT '
                            
    'for the threshold format. ',
                    default => 
    4000,
                    
    required => 1
            
    );

            
    $plugin->add_arg(
                    
    spec => 'hostname|H=s',
                    
    help => '-H=STRING:STRING .  See '
                            
    'Name of the hostname where the check is to be carried',
                    default => 
    'IEITT002',
            );

            
    $plugin->add_arg(
                    
    spec => 'Check|C=s',
                    
    help => '-C, --Check=STRING:STRING . Name of the check: ASP|DB|JOBS|AJ ',
                    default => 
    MSGQ,
                    
    required => 1
            
    );


            
    $plugin->getopts;

                    
    $plugin->set_thresholds(
                            
    warning  => $plugin->opts->warning,
                            
    critical => $plugin->opts->critical,
                    );

            if ( 
    $plugin->opts->verbose ) {
                    
    $DEBUG=1;
            };


    do {
            
    $t->open($plugin->opts->hostname);
            
    $login_screen_ok=$t->waitfor(   String => 'User',
                                            
    String => 'Benutzer',
                                            
    Errmode =>\&telnetError );
            if (
    $login_screen_ok) {
                    if (
    $DEBUG) {print "We have a complete login request\n"};
                     
    $t->print($username."\t".$password);
            } else {
                    if (
    $DEBUG) {print "We Failed to get a proper login screen. Attemp $login_screen_failed of $MAX_LOGIN_ATTEMPS \n"};
            }
    } while (
    $login_screen_ok==&& ($login_screen_failed<$MAX_LOGIN_ATTEMPS));

    while ((
    $qcmd_screen==0) && ($login_screen_failed<$MAX_LOGIN_ATTEMPS) && (!$login_impossible))
    {
            if (
    $DEBUG) {print("checking if the login screen is ok\n")};
            (
    $prematch$match) = $t->waitfor(
                                            
    String => '===>',
                                            
    String => 'CPF1107',
                                            
    String => 'CPF1120',
                                            
    String => 'is allocated to another job',
                                            
    String => 'Password has expired',
                                            
    String => 'password expires',
                                            
    String => 'Display Messages',
                                            
    String => 'Password will expire in',
                                            
    String => 'Previous sign-on'
            
    );
            if (
    $DEBUG) {print("we found: $match\n")};
    #       $t->buffer_empty;
            
    if ($match eq 'CPF1107') {
                    
    $t->print("");
                    if (
    $DEBUG) {print("CPF1107 - Pressing enter to get rid of the screen\n")};
            } 
    elsif ($match eq 'CPF1120') {
                    
    $t->print("");
                    if (
    $DEBUG) {print("CPF1120 - Pressing enter to get rid of the screen\n")};
            } 
    elsif ($match eq 'Previous sign-on') {
                    
    $t->print("");
                    if (
    $DEBUG) {print("Sign On info - Pressing enter to get rid of the screen\n")};
            } 
    elsif ($match eq 'is allocated to another job') {
                    
    $t->print("");
                    if (
    $DEBUG) {print("session allocated to another job - Pressing enter to get rid of the screeni\n")};
            } 
    elsif ($match eq 'Password has expired') {
                    
    $t->print("");
                    if (
    $DEBUG) {print("Password has expired - Pressing enter to get rid of the screen\n")};
                    
    $login_impossible 1;
            } 
    elsif ($match eq 'password expires') {
                    
    $t->print("");
                    if (
    $DEBUG) {print("password expires - Pressing enter to get rid of the screen\n")};
            } 
    elsif ($match eq 'Display Messages') {
                    
    $t->print("");
                    if (
    $DEBUG) {print("Display Messages - Pressing enter to get rid of the screen\n")};
            } 
    elsif ($match eq 'Password will expire in') {
                    
    $t->print("");
                    if (
    $DEBUG) {print("Password will expire in - Pressing enter to get rid of the screen\n")};
            } 
    elsif ($match eq '===>') {
                    
    $qcmd_screen=1;
                    if (
    $DEBUG) {print("We are in the main QCMD screen\n")};
            }
    }

    if (
    $qcmd_screen==1) {
            
    $t->buffer_empty;
            if (
    $DEBUG) {print("Sending wrkactjob command.\n")};
            
    $t->print("dspmsg QSYSOPR astlvl(*basic)");
            (
    $prematch$match) = $t->waitfor(
                                            
    String => 'F21=Select assistance level      F22=Display list details',
                                            
    String => 'F17=Top   F18=Bottom   F24=More keys');
            
    $prematch=~ s/\e|\[[0-9]*;[0-9]*H//g;
            
    $prematch=~ s/\[1m/ /g;
            
    $prematch=~ s/\[4m/    /g;
            
    $prematch=~ s/\[0m//g;
            
    $prematch=~ s/\[\?3l\[\?7h\[2J//g;

            
    @buffer_scrsplit('Messages needing a reply',$prematch);
            
    $messages_scr[email protected]buffer_scr[1];
            @
    reply_reqsplit('Messages not needing a reply ',$messages_scr);

            
    $wrk_scr[email protected]reply_req[0];
            
    $wrk_scr=~ s/                /\n/g;
            
    $wrk_scr=~ s/  +/ /g;
            
    $wrk_scr=~ s/\n\s+/\n/g;
            
    $wrk_scr=~ s/^\n//g;


            
    @lines=split(/\n/,$wrk_scr);

            if (
    $DEBUG) {print("Analizing DSPMSGQ information.\n")};

            if (
    $plugin->opts->Check eq "MSGQ") {
                    if (@
    lines[0eq "(No messages available)") {
                            
    $lines=0;
                            
    $output="No messages";
                    } else {
                            
    $linesscalar @lines;
                            
    $output "";
                            foreach 
    $message_index (0..$#lines) {
                                    
    $output$output $lines[$message_index] //";
                            }
                    }
                    
    $plugin->add_perfdatalabel => "Messages"value => $linesuom => "Messages"warning=> 1critical => 1);
            }
            
    $t->print("^[OR");
            
    $t->print("^[OR");
            
    $t->print("90\n");
            
    sleep(2);
                    
    $plugin->nagios_exit(
                            
    return_code => $plugin->check_threshold($lines),
                            
    message     => "Messages: $lines$output"
                    
    );
    }
    $plugin->nagios_exit(
            
    return_code => UNKNOWN,
            
    message     => "Couldn't retrieve information"
    ); 

    Leave a comment:


  • Ritchie_
    replied
    If you would do that... many thanks :-)

    Leave a comment:


  • BigFredi
    replied
    Re: Qsysopr messages needs to return ok, warning or critical Help

    I tried that approach using perl, and it was madness with all those positioning characters. I had 2 extra problems anyway, as I had iSeries in 10 different languages, and some of them requiring a devname, so I had to fight my login process. Anyway, if your system is in English, what I had was quite functional and did page down to catch all the messages.

    Anyway, to avoid all those messy codes and be more compliance acceptable, I ended using jtopen to retrieve the messages, processes and subsystems. I could take a look in my backups for my perl code if you are interested.

    From my phone using Tapatalk

    Leave a comment:


  • Ritchie_
    replied
    THat would mean you would need to capture the seperate messages, which I have not been able to do...due to how the captured data is in the output file

    Leave a comment:


  • AkHeNaToN
    replied
    while loop to parse all messages ?

    Leave a comment:


  • Qsysopr messages needs to return ok, warning or critical Help

    on an iseries we are trying to monitor messages in the Qsysopr queue

    We have the following script
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~
    #!/bin/bash
    (sleep 1; echo -e "USERID\t"; echo -e "PASSWORD\r"; sleep 1; echo -e "\r"; echo -e "DSPMSG QSYSOPR \r"; sleep 1; echo -e "\033[6~";echo -e "\033[6~";echo -e "\033[6~"; sleep 1; echo -e "\033[13~"; echo -e "90\r";sleep 10) | telnet SERVERNAME > /usr/local/nagios/libexec/outputfile.txt 2> /dev/null
    if egrep -i "(No messages available)|A door, cover, or interlock is open on device|A paper jam has occurred on device|PWS3006 received by procedure|Verify alignment on printer|A printer supply needs attention on device" /usr/local/nagios/libexec/outputfile.txt -q
    then echo 'OK - No Messages Available'; exit 0
    else
    if grep "This is a test massage to keep the warning line in the check" /usr/local/nagios/libexec/outputfile.txt -q
    then echo 'WARNING - Message(s) Waiting for answering in QSYSOPR ON SERVERNAME Server'; exit 1
    else
    echo 'CRITICAL: Message(s) Waiting for answering in QSYSOPR ON SERVERNAME Server'; exit 2
    fi
    fi
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~

    this works if there would be only one message in the queue, however when there are more message this does not work correctly.
    Let's say there are the messages 'A paper jam has occurred' (message labelled as OK) and 'No media of class found' (to be labeled as critical) in the queue. This then would exit with an okay as it will recognize the paper jam message and
    then exit with an okay state ignoring the 'No media of class' message which will need to trigger a critical.
    Additional problem is that the output file does contain 'garbage' characters and not just lines of text.
    example:
    Trying IP.AD.DR.ESS...
    Connected to SERVERNAME.
    Escape character is '^]'.
    [?3l[?7h[7;53H[?3l[?7h[1;1H[2J[0m [1;22H[1m[0m [1m Sign On [0m [2;2H[0m [0m [2;47H System . . . . . : SERVERNAME [0m [0m [3;47H Subsystem . . . . : QINTER [0m [0m [4;47H Display . . . . . : QPADEV000X [7;16H User . . . . . . . . . . . . . . [4m[0m [4m [0m [8;16H Password . . . . . . . . . . . . [0m [0m [9;16H[0m [0m [0m [0m [11;1H _______________ [7m[0m [7m [0m [7m[0m [7m [0m [11;46H[7m[0m [7m [0m ______________ _____________ [7m[0m [7m [0m [12;33H[7m[0m [7m [0m [12;46H[7m[0m [7m [0m [12;60H ____________ [13;5H ___________ [7m[0m [7m [0m [13;33H[7m[0m [7m [0m [13;46H[7m[0m [7m [0m [13;60H __________ [14;7H _________ [7m[0m [7m [0m [7m[0m [7m [0m [14;46H[7m[0m [7m [0m [14;60H ________ [15;9H _______ [7m[0m [7m [0m [15;33H[7m[0m [7m [0m [15;46H[7m[0m [7m [0m [15;60H ______ [16;12H ____ [7m[0m [7m [0m [16;33H[7m[0m [7m [0m [16;46H[7m[0m [7m [0m [16;60H ____ [17;14H __ [7m[0m [7m [0m [7m[0m [7m [0m [7m[0m [7m [0m __ [19;23H COMPANY NAME [21;14H Ongeoorloofd gebruik van dit systeem is verboden [22;15H Unauthorized use of this system is prohibited [24;39H[1m[0m [1m (C) COPYRIGHT IBM CORP. 1980, 2005. [0m [7;53H[7;53H[4mNAGIOS[8;53H[0m [7;53H[1;1H[1;1H[?3l[?7h[1;1H[2J[0m [0m [0m [0m [0m [1m[0m [1m Display Program Messages [0m [1;65H[1;65H[3;1H[1m[0m [1mJob 004167/NAGIOS/QPADEV000X started on 27/11/12 at 10:23:59 in subsystem QI[0m [4;1H[1m[0m [1mMessage queue NAGIOS is allocated to another job. [0m [4;79H[19;1H Press Enter to continue. [23;1H F3=Exit F12=Cancel [23;33H[?3l[?7h[1;1H[2J [1;1H[1;1H[20;7H[?3l[?7h[1;1H[2J MAIN [1;32H[1m[0m [1mi5/OS Main Menu[0m [2;2H[0m [0m [0m [0m [2;61H System: SERVERNAME Select one of the following: [5;6H 1. User tasks [6;6H 2. Office tasks [8;6H 4. Files, libraries, and folders [10;6H 6. Communications [12;6H 8. Problem handling [13;6H 9. Display a menu [14;5H 10. Information Assistant options [15;5H 11. iSeries Access tasks [17;5H 90. Sign off [19;1H Selection or command [20;1H ===>[4m[0m [4m [0m F3=Exit F4=Prompt F9=Retrieve F12=Cancel F13=Information Assistant F23=Set initial menu [24;1H[1m[0m [1m(C) COPYRIGHT IBM CORP. 1980, 2005. [0m [1m [0m [20;7H[20;7H[20;7H[4mDSPMSG QSYSOPR [0m[10;3H[?3l[?7h[1;1H[2J [1;31H[1m[0m [1mWork with Messages[0m [2;2H[0m [0m [0m [0m [2;61H System: SERVERNAME Messages in: QSYSOPR [5;1H Type options below, then press Enter. [6;3H 5=Display details and reply [8;1H[1m[0m [1mOpt[0m [1m[0m [1mMessage[0m [9;2H [1m[0m [1m Messages needing a reply [0m [4m[0m [4m [0m This is a TEST[10;80H From . . : USERNAME 27/11/12 10:19:48[11;80H [4m[0m [4m [0m Verify alignment on printer ZBRVAL. (I G N R E C)[12;80H [4m[0m [4m [0m Verify alignment on printer NLST618P. (I G N R E C)[13;80H [4m[0m [4m [0m Verify alignment on printer NLST610P. (I G N R E C)[14;80H [4m[0m [4m [0m Verify alignment on printer NLST610P. (I G N R E C)[15;80H [4m[0m [4m [0m PWS3006 received by procedure RRR1003. (C D I R)[16;80H [17;80H [1m[0m [1m Messages not needing a reply [0m [4m[0m [4m [0m Job message queue for 003685/QUSER/QZDASOINIT has been wrapped.[19;80H [4m[0m [4m [0m Heartbeat from SERVERNAME. (121127 101545)[20;80H [21;65H[0m[0m [0m [0m[1m[0m [1m

    ( before the [ there are actually arrows pointing to the left which the post do now not show)

    Unfortunately i'm not a programmer nor have much experience in it so I do have problems getting it to work in a proper way.
    So if anyone could shine a light on this so it will do the checks and after this reports the worst return code based on the text found that would be great.lets say if there are two messages, one or an OK and one for a warning then the warning should be reported. Or a warning and a critical then the critical should be returned.
    (the normal as400_check plugin does only return if there is one or more messages but does not classify them based on given parameters)
Working...
X