How To Set UNIX Rules To Fire Events For Individual Objects

The Argent UNIX Rules are typically configured to fire a single event for the condition as a whole – the entire Rule’s script is treated as a Boolean Pass or Fail

For example, take the bundled SCP_LINUX_DISK_SPACE_20

This Rule is broken if any file system tested by the Rule’s script has less than 20% free space

But only a single event is fired for all the file systems that have less than 20% free space

As a result, the condition won’t corrected unless all the file systems have more than 20% free space

The bundled Rule SCP_LINUX_DISK_SPACE_20 in Argent AT fires separate events by default

The internal mechanism to identify an event as the same ‘Argent AT event‘ is to compare following fields:

  • Node name
  • Relator name
  • Rule name
  • Comparison string

The enhanced Rule script should looks like:

#!/bin/sh

#

# SCP_LINUX_DISK_SPACE_20.TXT

#

# This script returns XML data to The Argent Guardian service running on W2000

#

# The output will be the ASCII string of ‘PASS‘ or ‘FAIL

#

#

#

#

# Copyright (c) 2005 ArgSoft Intellectual Property Holdings, Limited

#

# All Rights Reserved

#

# ArgSoft Intellectual Property Holdings, Limited

#

#

# This is PROPRIETARY SOURCE CODE of ArgSoft Intellectual Property Holdings, Limited

#

# The contents of this file may not be disclosed to third parties, copied or

# duplicated in any form, in whole or in part, without the prior written

# permission of ArgSoft Intellectual Property Holdings, Limited

#

# RESTRICTED RIGHTS LEGEND:

# Use, duplication or disclosure by the Government is subject to restrictions

# as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data

# and Computer Software clause at DFARS 252.227-7013, and/or in similar or

# successor clauses in the FAR, DOD or NASA FAR Supplement

#

# Unpublished – rights reserved under the Copyright Laws of the United States

# and other countries

#

#

#

#

# This Rule uses df to check for filesystems free space

#

# The Rule fails if there is less than 20% free space

#

# For more information: email Unix@Argent.com

STATUS=NOVAL

SUMMARY=NOVAL

COMMENT=NOVAL

#

# xmlOut() – prints an entire XML output for a command script

#

# Used for The Argent Guardian Rules that return a PASS/FAIL

#

# status and summary and comment descriptions

#

xmlOut()

{

xmlBegin

xmlStatus

xmlEnd

}

#

# xmlBegin() – Prints out the definition of the XML format used to

#

# send status data to The Argent Guardian

#

xmlBegin()

{

cat <<!

<?xml version=”1.0″?>

<!DOCTYPE TAGResult

[

<!ELEMENT TAGResult (QEResult+)>

<!ELEMENT QEResult (status, summary, comment)>

<!ELEMENT status (#PCDATA)> <!– (PASS | FAIL) –>

<!ELEMENT summary (#PCDATA) >

<!ELEMENT comment (#PCDATA) >

]>

<TAGResult>

!

} # End of xmlBegin()

#

# xmlStatus() – Send a status block to The Argent Guardian. The

#

# status should be ‘PASS’ or ‘FAIL’. The summary explains the result

#

# and the comment is a generic description of the Unix Rule

#

xmlStatus()

{

cat <<!

<QEResult>

<status>$STATUS</status>

<summary>$SUMMARY</summary>

<comment>$COMMENT</comment>

</QEResult>

!

} # End of xmlStatus()

#

# xmlEnd() – Completes the XML data block

#

xmlEnd()

{

cat <<!

</TAGResult>

!

} # End of xmlEnd()

############################# Main portion of script ##########################

#

# Set the IFS variable, which is used by the read command to parse input

#

# We wish to read the input one line at a time

#

IFS=”

#

# Use the df command to get information about the filesystems

#

DFCMD=”df -k”

#

# The FREE_PCT variable defines the minimum percentage of free disk space

#

# for each filesystem

#

FREE_PCT=60

#

# Define any directories you wish to ignore here. Directory variables

#

# should start at ‘1’ and increment continuously. The following are

#

# three example variables (that would need to be uncommented)

#

#IGNORE1=”/usr”

#IGNORE2=”/”

#IGNORE3=”/tmp”

#

# Assume the status of the Rule is OK

#

STATUS=PASS

EXIT_CODE=0

SUMMARY=”All filesystems have at least ${FREE_PCT}% of their space free”

COMMENT=”Used ${DFCMD} to get File System capacities”

xmlBegin

#

# Iterate through all the filesystems

#

for fs in ‘eval $DFCMD’; do

#

# FS is the actual filesystem, MNT is the mounted directory. Include

#

# an ‘x’ before the line in case the filesystem is blank

#

FS=`echo $fs | awk ‘ { print $1 } ‘`

MNT=`echo x$fs | awk ‘ { print $6 } ‘`

#

# Skip the first line of DFCMD, which is the column headers

#

if [ “$FS” = “Filesystem” ]; then

continue

fi

#

# Derive the free space from the capacity used and compare it to

#

# the threshold

#

CAPACITY=`echo $fs | awk ‘ { print $5 } ‘`

CAPACITY=`echo $CAPACITY | sed ‘s/%//’`

FREE_SPACE=`expr 100 – $CAPACITY`

if [ “$FREE_SPACE” -lt “$FREE_PCT” ]; then

#

# Make sure we don’t wish to ignore the directory

#

ignoredir=””

igcount=1

#

# Create the ‘testvar’ variable, and iterate until it is blank

#

eval testvar=”\$IGNORE${igcount}”

until [ “x$testvar” = “x” ]; do

if [ “x$testvar” = “x$MNT” ]; then

ignoredir=1

fi

igcount=`expr $igcount + 1`

eval testvar=”\$IGNORE${igcount}”

done

if [ “x$ignoredir” != “x” ]; then

#

# Ignore this directory

#

continue;

fi

STATUS=FAIL

EXIT_CODE=1

SUMMARY=”File System $MNT (${FREE_SPACE}%) has less than ${FREE_PCT}% Free Space.”

xmlStatus

fi

done

if [ $STATUS = “PASS” ]; then

xmlStatus

fi

xmlEnd

exit $EXIT_CODE

When individual file system, say ‘/ext11‘, does not break the Rule any more, the event for file system ‘/ext11‘ will be corrected while leaving the event for file system ‘/ext12‘ pending