view usr/src/cmd/fm/scripts/dictck.pl @ 12979:ab9ae749152f

PSARC/2009/617 Software Events Notification Parameters CLI PSARC/2009/618 snmp-notify: SNMP Notification Daemon for Software Events PSARC/2009/619 smtp-notify: Email Notification Daemon for Software Events PSARC/2010/225 fmd for non-global Solaris zones PSARC/2010/226 Solaris Instance UUID PSARC/2010/227 nvlist_nvflag(3NVPAIR) PSARC/2010/228 libfmevent additions PSARC/2010/257 sysevent_evc_setpropnvl and sysevent_evc_getpropnvl PSARC/2010/265 FMRI and FMA Event Stabilty, 'ireport' category 1 event class, and the 'sw' FMRI scheme PSARC/2010/278 FMA/SMF integration: instance state transitions PSARC/2010/279 Modelling panics within FMA PSARC/2010/290 logadm.conf upgrade 6392476 fmdump needs to pretty-print 6393375 userland ereport/ireport event generation interfaces 6445732 Add email notification agent for FMA and software events 6804168 RFE: Allow an efficient means to monitor SMF services status changes 6866661 scf_values_destroy(3SCF) will segfault if is passed NULL 6884709 Add snmp notification agent for FMA and software events 6884712 Add private interface to tap into libfmd_msg macro expansion capabilities 6897919 fmd to run in a non-global zone 6897937 fmd use of non-private doors is not safe 6900081 add a UUID to Solaris kernel image for use in crashdump identification 6914884 model panic events as a defect diagnosis in FMA 6944862 fmd_case_open_uuid, fmd_case_uuisresolved, fmd_nvl_create_defect 6944866 log legacy sysevents in fmd 6944867 enumerate svc scheme in topo 6944868 software-diagnosis and software-response fmd modules 6944870 model SMF maintenance state as a defect diagnosis in FMA 6944876 savecore runs in foreground for systems with zfs root and dedicated dump 6965796 Implement notification parameters for SMF state transitions and FMA events 6968287 SUN-FM-MIB.mib needs to be updated to reflect Oracle information 6972331 logadm.conf upgrade PSARC/2010/290
author Gavin Maltby <gavin.maltby@oracle.com>
date Fri, 30 Jul 2010 17:04:17 +1000
parents 2a58fa6611ef
children
line wrap: on
line source

#!/usr/bin/perl -w
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
#
#
# dictck -- Sanity check a .dict file and optionally the corresponding .po file
#
# example: dickck FMD.dict FMD.po
#
# usage: dickck [-vp] [ -b buildcode ] dictfile [ pofile ]
#
#	-b	specify location of "buildcode" command
#
#	-p	print a .po file template to stdout, based on dictfile given
#
#	-v	verbose, show how code is assembled
#
# Note: this program requires the "buildcode" program in your search path.
#

use strict;

use Getopt::Std;

use vars qw($opt_b $opt_p $opt_v);

my $Myname = $0;	# save our name for error messages
$Myname =~ s,.*/,,;

$SIG{HUP} = $SIG{INT} = $SIG{TERM} = $SIG{__DIE__} = sub {
	# although fatal, we prepend "WARNING:" to make sure the
	# commonly-used "nightly" script flags this as lint on the .dict file
	die "$Myname: WARNING: @_";
};

#
# Category 1 event classes
#
my @cat1ev = qw(fault defect upset ereport list ireport);

#
# usage -- print a usage message and exit
#
sub usage {
	my $msg = shift;

	warn "$Myname: $msg\n" if defined($msg);
	warn "usage: $Myname [-pv] [ -b buildcode ] dictfile [ pofile ]\n";
	exit 1;
}

my %keys2val;
my %val2keys;
my %code2val;

my $buildcode = 'buildcode';

#
# the "main" for this script...
#
getopts('b:pv') or usage;

my $dictfile = shift;
my $pofile = shift;
usage unless defined($dictfile);
usage if @ARGV;
$buildcode = $opt_b if defined($opt_b);
dodict($dictfile);
dopo($pofile) if defined($pofile);
exit 0;

#
# dodict -- load up a .dict file, sanity checking it as we go
#
sub dodict {
	my $name = shift;
	my $dname;
	my $line = 0;
	my $lhs;
	my $rhs;
	my %props;
	my $maxkey = 1;

	if ($name =~ m,([^/]+)\.dict$,) {
		$dname = $1;
	} else {
		die "dictname \"$name\" not something.dict as expected\n";
	}

	open(F, $name) or die "$name: $!\n";
	print "parsing \"$name\"\n" if $opt_v;
	while (<F>) {
		$line++;
		next if /^\s*#/;
		chomp;
		next if /^\s*$/;
		die "$name:$line: first non-comment line must be FMDICT line\n"
		    unless /^FMDICT:/;
		print "FMDICT keyword found on line $line\n" if $opt_v;
		s/FMDICT:\s*//;
		my $s = $_;
		while ($s =~ /^\s*([^=\s]+)(.*)$/) {
			$lhs = $1;
			$rhs = "";
			$s = $+;
			if ($s =~ /^\s*=\s*(.*)$/) {
				$s = $+;
				die "$name:$line: property \"$lhs\" incomplete\n"
				    unless $s ne "";
			}
			if ($s =~ /^"((?:[^"]|\\")*)"(.*)$/) {
				$s = $+;
				$rhs = $1;
			} else {
				$s =~ /^([^\s]*)(.*)$/;
				$s = $+;
				$rhs = $1;
			}
			$rhs =~ s/\\(.)/dobs($1)/ge;
			$props{$lhs} = $rhs;
			print "property \"$lhs\" value \"$rhs\"\n" if $opt_v;
		}
		last;
	}
	# check for required headers
	die "$name: no version property in header\n"
	    unless defined($props{'version'});
	die "$name: no name property in header\n"
	    unless defined($props{'name'});
	die "$name: no maxkey property in header\n"
	    unless defined($props{'maxkey'});

	# check version
	die "$name:$line: unexpected version: \"$props{'version'}\"\n"
	    unless $props{'version'} eq "1";

	# check name
	die "$name:$line: name \"$props{'name'}\" doesn't match \"$dname\" from filename\n"
	    unless $props{'name'} eq $dname;

	# check format of maxkey (value checked later)
	die "$name:$line: maxkey property must be a number\n"
	    unless $props{'maxkey'} =~ /^\d+$/;

	# check for old bits property
	die "$name: obsolete \"bits\" property found in header\n"
	    if defined($props{'bits'});

	# parse entries
	while (<F>) {
		$line++;
		chomp;
		s/#.*//;
		next if /^\s*$/;
		die "$name:$line: malformed entry\n"
		    unless /^([^=]+)=(\d+)$/;
		$lhs = $1;
		$rhs = $2;

		# make sure keys are sorted
		my $elhs = join(' ', sort split(/\s/, $lhs));
		die "$name:$line: keys not in expected format of:\n" .
		    "    \"$elhs\"\n"
		    unless $elhs eq $lhs;

		# check for duplicate or unexpected keys
		my %keys;
		my $cat1pat = join('|', @cat1ev);
		foreach my $e (split(/\s/, $lhs)) {
			die "$name:$line: unknown event type \"$e\"\n"
			    unless $e =~
			    /^($cat1pat)\..*[^.]$/;
			die "$name:$line: key repeated: \"$e\"\n"
			    if defined($keys{$e});
			$keys{$e} = 1;
		}
		$maxkey = keys(%keys) if $maxkey < keys(%keys);

		die "$name:$line: duplicate entry for keys\n"
		    if defined($keys2val{$lhs});
		die "$name:$line: duplicate entry for value $rhs\n"
		    if defined($val2keys{$rhs});
		$keys2val{$lhs} = $rhs;
		$val2keys{$rhs} = $lhs;

		open(B, "$buildcode $dname $rhs|") or
		    die "can't run buildcode: $!\n";
		my $code = <B>;
		chomp $code;
		close(B);
		print "code: $code keys: $lhs\n" if $opt_v;
		$code2val{$code} = $rhs;

		if ($opt_p) {
			print <<EOF;
#
# code: $code
# keys: $lhs
#
msgid "$code.type"
msgstr "XXX"
msgid "$code.severity"
msgstr "XXX"
msgid "$code.description"
msgstr "XXX"
msgid "$code.response"
msgstr "XXX"
msgid "$code.impact"
msgstr "XXX"
msgid "$code.action"
msgstr "XXX"
EOF
		}
	}

	print "computed maxkey: $maxkey\n" if $opt_v;

	# check maxkey
	die "$name: maxkey too low, should be $maxkey\n"
	    if $props{'maxkey'} < $maxkey;

	close(F);
}

#
# dobs -- handle backslashed sequences
#
sub dobs {
	my $s = shift;

	return "\n" if $s eq 'n';
	return "\r" if $s eq 'r';
	return "\t" if $s eq 't';
	return $s;
}

#
# dopo -- sanity check a po file
#
sub dopo {
	my $name = shift;
	my $line = 0;
	my $id;
	my $code;
	my $suffix;
	my %ids;

	open(F, $name) or die "$name: $!\n";
	print "parsing \"$name\"\n" if $opt_v;
	while (<F>) {
		$line++;
		next if /^\s*#/;
		chomp;
		next if /^\s*$/;
		next unless /^msgid\s*"([^"]+)"$/;
		$id = $1;
		next unless $id =~
		   /^(.*)\.(type|severity|description|response|impact|action)$/;
		$code = $1;
		$suffix = $2;
		die "$name:$line: no dict entry for code \"$code\"\n"
		   unless defined($code2val{$code});
		$ids{$id} = $line;
	}
	close(F);

	# above checks while reading in file ensured that node code was
	# mentioned in .po file that didn't exist in .dict file.  now
	# check the other direction: make sure the full set of entries
	# exist for each code in the .dict file
	foreach $code (sort keys %code2val) {
		die "$name: missing entry for \"$code.type\"\n"
		    unless defined($ids{"$code.type"});
		die "$name: missing entry for \"$code.severity\"\n"
		    unless defined($ids{"$code.severity"});
		die "$name: missing entry for \"$code.description\"\n"
		    unless defined($ids{"$code.description"});
		die "$name: missing entry for \"$code.response\"\n"
		    unless defined($ids{"$code.response"});
		die "$name: missing entry for \"$code.impact\"\n"
		    unless defined($ids{"$code.impact"});
		die "$name: missing entry for \"$code.action\"\n"
		    unless defined($ids{"$code.action"});
	}
}