/perl/dev/SLE/proc_zstate-00001.pl
Perl | 138 lines | 83 code | 8 blank | 47 comment | 0 complexity | 2020a288c8f507b8668f590c889afa3c MD5 | raw file
- #!/usr/bin/perl -w
- #<<BEGIN PATTERN METADATA>>
- #META-CATEGORY = SLE
- #META-REVISION = 1.0.8
- #META-TITLE = Basic Health Check - Zombie Processes
- #META-DESCRIPTION = Checks for excessive zombie processes
- #META-PRODUCT = Basic
- #META-OS = SUSE
- #META-DISTRO = SLE
- #META-ARCH = All
- #META-LINK-TID = http://www.suse.com/support/kb/doc.php?id=7002724
- #<<END PATTERN METADATA>>
- ##############################################################################
- # WARNING WARNING WARNING WARNING WARNING WARNING WARNING
- # This pattern uses deprecated functions. Do not use as an example.
- ##############################################################################
- ##############################################################################
- # Copyright (C) 2009 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, write to the Free Software
- # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- #
- # Authors/Contributors:
- # Jason Record (jrecord@suse.com) - original BASH script
- # Douglas Kimball (dkimball@novell.com) - translated to this Perl script
- #
- # Creation Date: 2009 Feb 4
- # Last Modified Date: 2009 Jul 28
- #
- ##############################################################################
- ##############################################################################
- # Module Definition
- ##############################################################################
- use strict;
- use warnings; # should be same as -w command option
- use SDP::Core;
- use SDP::SUSE;
- ##############################################################################
- # Constants
- ##############################################################################
- use constant LIMIT_OPT_PROCZRED => 10; # Number of Z state proceses; red
- use constant LIMIT_OPT_PROCZYEL => 5; # Number of Z state proceses; yellow
- use constant OPEN_FILE_ERROR => "ERROR: Couldn't open file: ";
- use constant SECTION_PROCS => "egrep";
- use constant PATTERN_GREP => ".*?";
- use constant PROPERTY_NAME_PROCZ => 'PROCZ';
- ##############################################################################
- # Overriden (eventually or in part) from SDP::Core Module
- ##############################################################################
- $META_CATEGORY = "SLE"; #Assign it the same as the META_CATEGORY above
- $PRIMARY_LINK = "META-LINK-TID";
- @PATTERN_RESULTS = (
- PROPERTY_NAME_CATEGORY."=$META_CATEGORY",
- PROPERTY_NAME_PATTERN_ID."=$PATTERN_ID",
- PROPERTY_NAME_PRIMARY_LINK."=$PRIMARY_LINK",
- PROPERTY_NAME_OVERALL."=$GSTATUS",
- PROPERTY_NAME_OVERALL_INFO."=None"
- );
- $ARCH_FILE = "basic-health-check.txt";
- ##############################################################################
- # Feature Subroutines
- ##############################################################################
- # Check Free Memory and Disk Swapping
- sub check_proc_zstate() {
- print("Zombie Processes\n") if $OPT_LOGLEVEL >= LOGLEVEL_DEBUG;
- print("Using: $SRC_FILE1\n") if $OPT_LOGLEVEL >= LOGLEVEL_DEBUG;
-
- # df -h display mounted file systems
- my @ALL_VMSTAT_LINES = SDP::Core::grep_section_lines_wrap(SECTION_PROCS, PATTERN_GREP);
- my @VMSTAT_LINE = ();
-
- my $Z_COUNT = 0; # number of Z state processes
-
- print("Line count: ".$#ALL_VMSTAT_LINES."\n") if $OPT_LOGLEVEL >= LOGLEVEL_DEBUG;
- foreach my $i (0 .. $#ALL_VMSTAT_LINES) {
- @VMSTAT_LINE = @{$ALL_VMSTAT_LINES[$i]};
- print("@VMSTAT_LINE\n") if $OPT_LOGLEVEL >= LOGLEVEL_DEBUG;
- print(" $VMSTAT_LINE[7]\n") if $OPT_LOGLEVEL >= LOGLEVEL_DEBUG && $VMSTAT_LINE[7];
- if($VMSTAT_LINE[7] && $VMSTAT_LINE[7] eq 'Z') {
- $Z_COUNT++;
- print("$Z_COUNT\n") if $OPT_LOGLEVEL >= LOGLEVEL_DEBUG;
- }
- }
-
- # check against thresholds for status and message
- if ( $Z_COUNT >= LIMIT_OPT_PROCZRED ) {
- SDP::Core::update_status(STATUS_CRITICAL, PROPERTY_NAME_PROCZ, "$Z_COUNT meets or exceeds ".LIMIT_OPT_PROCZRED." zombie processes");
- }
- elsif ( $Z_COUNT >= LIMIT_OPT_PROCZYEL ) {
- SDP::Core::update_status(STATUS_WARNING, PROPERTY_NAME_PROCZ, "$Z_COUNT meets or exceeds ".LIMIT_OPT_PROCZYEL." zombie processes");
- }
- else {
- SDP::Core::initialize_status(STATUS_SUCCESS, "Observed $Z_COUNT zombie processes");
- SDP::Core::update_status(STATUS_SUCCESS, PROPERTY_NAME_PROCZ, "Observed $Z_COUNT zombie processes");
- }
- }
- ##############################################################################
- # Program execution subroutine
- ##############################################################################
- sub main() {
- SDP::Core::process_options(); # process any usage of command line options (such as -c for conf file)
- $SRC_FILE1 = $ARCH_PATH . $ARCH_FILE;
- # load_conf_file(); # load conf file based on process_options or default setting of $PATTERN_CONF
- SDP::Core::init_file_sections(); # core init
- check_proc_zstate();
- SDP::Core::print_pattern_results();
- }
- # call the main driver/subroutine then exit clean
- main();
- exit;