#!/usr/bin/perl
#
# tty_console_log_level
#   Health check program for the Linux Health Checker
#
# Copyright IBM Corp. 2012
#
# Author(s): Aruna Balakrishnaiah <aruna@linux.vnet.ibm.com>
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors: See file CONTRIBUTORS which is part of this package
#

use strict;
use warnings;

use lib $ENV{"LNXHC_LIBDIR"};
use LNXHC::Check::Base;
use LNXHC::Check::Util qw/load_sysctl/;

# Exception IDs
my $LNXHC_EXCEPTION_LOW_LOGLEVEL = "low_loglevel";

# Value of parameter 'log_level'.
my $param_log_level = $ENV{"LNXHC_PARAM_log_level"};

# Path to the file containing data for sysinfo item 'printk'.
my $sysinfo_sysctl = $ENV{"LNXHC_SYSINFO_sysctl"};

check_int_param("log_level", 1, 8);

sub main()
{
	my $sysctl = load_sysctl($sysinfo_sysctl);
	die "Failed to read sysinfo: $sysinfo_sysctl: $!\n" unless $sysctl;

        my @console_loglevel = split(/\s+/, $sysctl->{'kernel.printk'});

	if ($console_loglevel[0] < $param_log_level) {
		lnxhc_exception($LNXHC_EXCEPTION_LOW_LOGLEVEL);
		lnxhc_exception_var("console_loglevel", $console_loglevel[0]);
	}
}
&main();
__DATA__
__END__
