# Copyright 09/07/01 Sun Microsystems, Inc. All Rights Reserved.
# pragma ident "@(#)t300-d.rul	1.3 01/09/07 Sun Microsystems"
#
#   File: t300-d.rul
#   Version: 1.0
#
# T300 Module Rules

#
# Rule 201
# Controller error
#
proc rple201 { action ruleId {rowName ""} {rowIndex 0} {matchList ""} } {
	set estatus "error"
	switch $action {
		condition {
			return 1
		}
		init {
			logSubscribe $ruleId /var/adm/t300.log "^................(\[^ \]*).*E: u(\[0-9\]+)ctr (.*)" $rowName $ruleId
			return ""
		}
		open {
			set host [ lindex $matchList 0 ]
			set idx [ lindex $matchList 1 ]
			set msg [ lindex $matchList 2 ]
			set longmsg [ format [ getRuleMsg irple201longmsg ] "$host" "$idx" "$msg" ]

			setRuleText $ruleId $rowName $estatus $longmsg
			logEvent $ruleId $rowName $estatus
			return ok
		}
		continue {
			return
		}
		ack {
			return
		}
		fix {
			return
		}
		close {
			return ok
		}
	}
}

#
# Rule 202
# Power/Cooling Unit error
#
proc rple202 { action ruleId {rowName ""} {rowIndex 0} {matchList ""} } {
	set estatus "error"

	switch $action {
		condition {
			return 1
		}
		init {
			logSubscribe $ruleId /var/adm/t300.log "^................(\[^ \]*).*E: u(\[0-9\]+)pcu(\[0-9\]+)(.*)" $rowName $ruleId
			return ""
		}
		open {
			set host [ lindex $matchList 0 ]
			set unitId [ lindex $matchList 1 ]
			set pcuId [ lindex $matchList 2 ]
			set msg [ lindex $matchList 3 ]
			set longmsg [ format [ getRuleMsg irple202longmsg ] "$host" "$unitId" "$pcuId" "$msg" ]

			setRuleText $ruleId $rowName $estatus $longmsg
			logEvent $ruleId $rowName $estatus
			return ok
		}
		continue {
			return
		}
		ack {
			return
		}
		fix {
			return
		}
		close {
			return ok
		}
	}
}

#
# Rule 203
# Loop Card error
#
proc rple203 { action ruleId {rowName ""} {rowIndex 0} {matchList ""} } {
	set estatus "error"

	switch $action {
		condition {
			return 1
		}
		init {
			logSubscribe $ruleId /var/adm/t300.log "^................(\[^ \]*).*E: u(\[0-9\]+)l(\[0-9\]+)(.*)" $rowName $ruleId
			return ""
		}
		open {
			set host [ lindex $matchList 0 ]
			set unitId [ lindex $matchList 1 ]
			set lcId [ lindex $matchList 2 ]
			set msg [ lindex $matchList 3 ]
			set longmsg [ format [ getRuleMsg irple203longmsg ] "$host" "$unitId" "$lcId" "$msg" ]

			setRuleText $ruleId $rowName $estatus $longmsg
			logEvent $ruleId $rowName $estatus
			return ok
		}
		continue {
			return
		}
		ack {
			return
		}
		fix {
			return
		}
		close {
			return ok
		}
	}
}

#
# Rule 204
# Disk error
#
proc rple204 { action ruleId {rowName ""} {rowIndex 0} {matchList ""} } {
	set estatus "error"

	switch $action {
		condition {
			return 1
		}
		init {
			logSubscribe $ruleId /var/adm/t300.log "^................(\[^ \]*).*E: u(\[0-9\]+)d(\[0-9\]+)(.*)" $rowName $ruleId
			return ""
		}
		open {
			set host [ lindex $matchList 0 ]
			set unitId [ lindex $matchList 1 ]
			set diskId [ lindex $matchList 2 ]
			set msg [ lindex $matchList 3 ]
			set longmsg [ format [ getRuleMsg irple204longmsg ] "$host" "$unitId" "$diskId" "$msg" ]

			setRuleText $ruleId $rowName $estatus $longmsg
			logEvent $ruleId $rowName $estatus
			return ok
		}
		continue {
			return
		}
		ack {
			return
		}
		fix {
			return
		}
		close {
			return ok
		}
	}
}

#
# Rule 205
# Controller warning
#
proc rple205 { action ruleId {rowName ""} {rowIndex 0} {matchList ""} } {
	set estatus "warning"

	switch $action {
		condition {
			return 1
		}
		init {
			logSubscribe $ruleId /var/adm/t300.log "^................(\[^ \]*).*W: u(\[0-9\]+)ctr (.*)" $rowName $ruleId
			return ""
		}
		open {
			set host [ lindex $matchList 0 ]
			set idx [ lindex $matchList 1 ]
			set msg [ lindex $matchList 2 ]
			set longmsg [ format [ getRuleMsg irple205longmsg ] "$host" "$idx" "$msg" ]

			setRuleText $ruleId $rowName $estatus $longmsg
			logEvent $ruleId $rowName $estatus
			return ok
		}
		continue {
			return
		}
		ack {
			return
		}
		fix {
			return
		}
		close {
			return ok
		}
	}
}

#
# Rule 206
# Power/Cooling Unit warning
#
proc rple206 { action ruleId {rowName ""} {rowIndex 0} {matchList ""} } {
	set estatus "warning"

	switch $action {
		condition {
			return 1
		}
		init {
			logSubscribe $ruleId /var/adm/t300.log "^................(\[^ \]*).*W: u(\[0-9\]+)pcu(\[0-9\]+)(.*)" $rowName $ruleId
			return ""
		}
		open {
			set host [ lindex $matchList 0 ]
			set unitId [ lindex $matchList 1 ]
			set pcuId [ lindex $matchList 2 ]
			set msg [ lindex $matchList 3 ]
			set longmsg [ format [ getRuleMsg irple206longmsg ] "$host" "$unitId" "$pcuId" "$msg" ]

			setRuleText $ruleId $rowName $estatus $longmsg
			logEvent $ruleId $rowName $estatus
			return ok
		}
		continue {
			return
		}
		ack {
			return
		}
		fix {
			return
		}
		close {
			return ok
		}
	}
}

#
# Rule 207
# Loop Card warning
#
proc rple207 { action ruleId {rowName ""} {rowIndex 0} {matchList ""} } {
	set estatus "warning"

	switch $action {
		condition {
			return 1
		}
		init {
			logSubscribe $ruleId /var/adm/t300.log "^................(\[^ \]*).*W: u(\[0-9\]+)l(\[0-9\]+)(.*)" $rowName $ruleId
			return ""
		}
		open {
			set host [ lindex $matchList 0 ]
			set unitId [ lindex $matchList 1 ]
			set lcId [ lindex $matchList 2 ]
			set msg [ lindex $matchList 3 ]
			set longmsg [ format [ getRuleMsg irple207longmsg ] "$host" "$unitId" "$lcId" "$msg" ]

			setRuleText $ruleId $rowName $estatus $longmsg
			logEvent $ruleId $rowName $estatus
			return ok
		}
		continue {
			return
		}
		ack {
			return
		}
		fix {
			return
		}
		close {
			return ok
		}
	}
}

#
# Rule 208
# Disk warning
#
proc rple208 { action ruleId {rowName ""} {rowIndex 0} {matchList ""} } {
	set estatus "warning"

	switch $action {
		condition {
			return 1
		}
		init {
			logSubscribe $ruleId /var/adm/t300.log "^................(\[^ \]*).*W: u(\[0-9\]+)d(\[0-9\]+)(.*)" $rowName $ruleId
			return ""
		}
		open {
			set host [ lindex $matchList 0 ]
			set unitId [ lindex $matchList 1 ]
			set diskId [ lindex $matchList 2 ]
			set msg [ lindex $matchList 3 ]
			set longmsg [ format [ getRuleMsg irple208longmsg ] "$host" "$unitId" "$diskId" "$msg" ]

			setRuleText $ruleId $rowName $estatus $longmsg
			logEvent $ruleId $rowName $estatus
			return ok
		}
		continue {
			return
		}
		ack {
			return
		}
		fix {
			return
		}
		close {
			return ok
		}
	}
}

#
# Rule 220
# Multi-disk failure error
#
proc rple220 { action ruleId {rowName ""} {rowIndex 0} {matchList ""} } {
	set estatus "error"

	switch $action {
		condition {
			return 1
		}
		init {
			logSubscribe $ruleId /var/adm/t300.log "^................(\[^ \]*).*E: Multi-disk failure(.*)" $rowName $ruleId
			return ""
		}
		open {
			set host [ lindex $matchList 0 ]
			set msg [ lindex $matchList 1 ]
			set longmsg [ format [ getRuleMsg irple220longmsg ] "$host" "$msg" ]

			setRuleText $ruleId $rowName $estatus $longmsg
			logEvent $ruleId $rowName $estatus
			return ok
		}
		continue {
			return
		}
		ack {
			return
		}
		fix {
			return
		}
		close {
			return ok
		}
	}
}

#
# Rule 221
# power/cooling unit error
#
proc rple221 { action ruleId {rowName ""} {rowIndex 0} {matchList ""} } {
	set estatus "error"

	switch $action {
		condition {
			return 1
		}
		init {
			logSubscribe $ruleId /var/adm/t300.log "^................(\[^ \]*).*E: Power On self test failed*" $rowName $ruleId
			return ""
		}
		open {
			set host [ lindex $matchList 0 ]
			set longmsg [ format [ getRuleMsg irple221longmsg ] "$host" ]

			setRuleText $ruleId $rowName $estatus $longmsg
			logEvent $ruleId $rowName $estatus
			return ok
		}
		continue {
			return
		}
		ack {
			return
		}
		fix {
			return
		}
		close {
			return ok
		}
	}
}

#
# Rule 222
# power/cooling unit error
#
proc rple222 { action ruleId {rowName ""} {rowIndex 0} {matchList ""} } {
	set estatus "error"

	switch $action {
		condition {
			return 1
		}
		init {
			logSubscribe $ruleId /var/adm/t300.log "^................(\[^ \]*).*E: u(\[0-9\]+)ctr1: Multiple Fan Faults;(.*)" $rowName $ruleId
			return ""
		}
		open {
			set host [ lindex $matchList 0 ]
			set idx [ lindex $matchList 1 ]
			set msg [ lindex $matchList 2 ]
			set longmsg [ format [ getRuleMsg irple222longmsg ] "$host" "$idx" "$msg" ]

			setRuleText $ruleId $rowName $estatus $longmsg
			logEvent $ruleId $rowName $estatus
			return ok
		}
		continue {
			return
		}
		ack {
			return
		}
		fix {
			return
		}
		close {
			return ok
		}
	}
}

#
# Rule 223
# controller warning
#
proc rple223 { action ruleId {rowName ""} {rowIndex 0} {matchList ""} } {
	set estatus "warning"

	switch $action {
		condition {
			return 1
		}
		init {
			logSubscribe $ruleId /var/adm/t300.log "^................(\[^ \]*).*W: SCSI Disk Error Occurred(.*)" $rowName $ruleId
			return ""
		}
		open {
			set host [ lindex $matchList 0 ]
			set msg [ lindex $matchList 1 ]
			set longmsg [ format [ getRuleMsg irple223longmsg ] "$host" "$msg" ]

			setRuleText $ruleId $rowName $estatus $longmsg
			logEvent $ruleId $rowName $estatus
			return ok
		}
		continue {
			return
		}
		ack {
			return
		}
		fix {
			return
		}
		close {
			return ok
		}
	}
}

#
# Rule 224
# Loop Card warning
#
proc rple224 { action ruleId {rowName ""} {rowIndex 0} {matchList ""} } {
	set estatus "warning"

	switch $action {
		condition {
			return 1
		}
		init {
			logSubscribe $ruleId /var/adm/t300.log "^................(\[^ \]*).*W: Loop (\[0-9\]+) may be bad(.*)" $rowName $ruleId
			return ""
		}
		open {
			set host [ lindex $matchList 0 ]
			set idx [ lindex $matchList 1 ]
			set msg [ lindex $matchList 2 ]
			set longmsg [ format [ getRuleMsg irple224longmsg ] "$host" "$idx" "$msg" ]

			setRuleText $ruleId $rowName $estatus $longmsg
			logEvent $ruleId $rowName $estatus
			return ok
		}
		continue {
			return
		}
		ack {
			return
		}
		fix {
			return
		}
		close {
			return ok
		}
	}
}

#
# Rule 225
# disk warning
#
proc rple225 { action ruleId {rowName ""} {rowIndex 0} {matchList ""} } {
	set estatus "warning"

	switch $action {
		condition {
			return 1
		}
		init {
			logSubscribe $ruleId /var/adm/t300.log "^................(\[^ \]*).*W: Sense(.*)" $rowName $ruleId
			return ""
		}
		open {
			set host [ lindex $matchList 0 ]
			set msg [ lindex $matchList 1 ]
			set longmsg [ format [ getRuleMsg irple225longmsg ] "$host" "$msg" ]

			setRuleText $ruleId $rowName $estatus $longmsg
			logEvent $ruleId $rowName $estatus
			return ok
		}
		continue {
			return
		}
		ack {
			return
		}
		fix {
			return
		}
		close {
			return ok
		}
	}
}

#
# Rule 226
# disk warning
#
proc rple226 { action ruleId {rowName ""} {rowIndex 0} {matchList ""} } {
	set estatus "warning"

	switch $action {
		condition {
			return 1
		}
		init {
			logSubscribe $ruleId /var/adm/t300.log "^................(\[^ \]*).*W: Valid Information(.*)" $rowName $ruleId
			return ""
		}
		open {
			set host [ lindex $matchList 0 ]
			set msg [ lindex $matchList 1 ]
			set longmsg [ format [ getRuleMsg irple226longmsg ] "$host" "$msg" ]

			setRuleText $ruleId $rowName $estatus $longmsg
			logEvent $ruleId $rowName $estatus
			return ok
		}
		continue {
			return
		}
		ack {
			return
		}
		fix {
			return
		}
		close {
			return ok
		}
	}
}

#
# Rule 227
# power/cooling unit warning
#
proc rple227 { action ruleId {rowName ""} {rowIndex 0} {matchList ""} } {
	set estatus "warning"

	switch $action {
		condition {
			return 1
		}
		init {
			logSubscribe $ruleId /var/adm/t300.log "^................(\[^ \]*).*W: SVD_PATH_FAILOVER:(.*)" $rowName $ruleId
			return ""
		}
		open {
			set host [ lindex $matchList 0 ]
			set msg [ lindex $matchList 1 ]
			set longmsg [ format [ getRuleMsg irple227longmsg ] "$host" "$msg" ]

			setRuleText $ruleId $rowName $estatus $longmsg
			logEvent $ruleId $rowName $estatus
			return ok
		}
		continue {
			return
		}
		ack {
			return
		}
		fix {
			return
		}
		close {
			return ok
		}
	}
}


#
# Rule 400
# fru/disk rule
# using fruState and fruStatus to decide whether the disk is normal
#
proc rple400 { action ruleId {rowName ""} {rowIndex 0} {matchList ""} } {
	switch $action {
		condition {
			ddl print debug " rple400 condition \n"

			set state [ getExternalRowValue $ruleId fruState $rowIndex ]
			set status [ getExternalRowValue $ruleId fruStatus $rowIndex ]

			set nodename [ getExternalRowValue $ruleId sunSmNodeName $rowName ]
			setRuleParm DYN $ruleId $rowName cur_node $nodename

			expr { ($state != "enabled") || ($status != "ready") }
		}

		init {
			ddl print debug " rple400 init \n"
			return ""
		}

		open {
			ddl print debug " rple400 open \n"

			set nodename [ getRuleParm DYN $ruleId $rowName cur_node ]
			set state [ getExternalRowValue $ruleId fruState $rowIndex ]
			set status [ getExternalRowValue $ruleId fruStatus $rowIndex ]

			set longmsg [ format [ getRuleMsg irple400longmsg ] "$nodename" "$state" "$status" ]

			if { $status == "fault" } {
				setRuleText $ruleId $rowName error $longmsg
				return error
			} else {
				setRuleText $ruleId $rowName warning $longmsg
				return warning
			}
		}

		continue {
			ddl print debug " rple400 continue \n"

			set nodename [ getRuleParm DYN $ruleId $rowName cur_node ]
			set state [ getExternalRowValue $ruleId fruState $rowIndex ]
			set status [ getExternalRowValue $ruleId fruStatus $rowIndex ]

			set longmsg [ format [ getRuleMsg irple400longmsg ] "$nodename" "$state" "$status" ]

			if { $status == "fault" } {
				setRuleText $ruleId $rowName error $longmsg
				return error
			} else {
				setRuleText $ruleId $rowName warning $longmsg
				return warning
			}
		}

		ack {
			return ""
		}

		fix {
			return ""
		}

		close {
			ddl print debug " rple400 close \n"
			return ok
		}
	}
}


#
# Rule 401
# fru/controller rule
# using fruState and fruStatus to decide whether the controller is normal
#
proc rple401 { action ruleId {rowName ""} {rowIndex 0} {matchList ""} } {
	switch $action {
		condition {
			ddl print debug " rple401 condition \n"

			set state [ getExternalRowValue $ruleId fruState $rowIndex ]
			set status [ getExternalRowValue $ruleId fruStatus $rowIndex ]

			set nodename [ getExternalRowValue $ruleId sunSmNodeName $rowName ]
			setRuleParm DYN $ruleId $rowName cur_node $nodename

			expr { ($state != "enabled") || ($status != "ready") }
		}

		init {
			ddl print debug " rple401 init \n"
			return ""
		}

		open {
			ddl print debug " rple401 open \n"

			set nodename [ getRuleParm DYN $ruleId $rowName cur_node ]
			set state [ getExternalRowValue $ruleId fruState $rowIndex ]
			set status [ getExternalRowValue $ruleId fruStatus $rowIndex ]

			set longmsg [ format [ getRuleMsg irple400longmsg ] "$nodename" "$state" "$status" ]

			if { $status == "fault" } {
				setRuleText $ruleId $rowName error $longmsg
				return error
			} else {
				setRuleText $ruleId $rowName warning $longmsg
				return warning
			}
		}

		continue {
			ddl print debug " rple401 continue \n"

			set nodename [ getRuleParm DYN $ruleId $rowName cur_node ]
			set state [ getExternalRowValue $ruleId fruState $rowIndex ]
			set status [ getExternalRowValue $ruleId fruStatus $rowIndex ]

			set longmsg [ format [ getRuleMsg irple401longmsg ] "$nodename" "$state" "$status" ]

			if { $status == "fault" } {
				setRuleText $ruleId $rowName error $longmsg
				return error
			} else {
				setRuleText $ruleId $rowName warning $longmsg
				return warning
			}
		}

		ack {
			return ""
		}

		fix {
			return ""
		}

		close {
			ddl print debug " rple401 close \n"
			return ok
		}
	}
}


#
# Rule 402
# fru/loop-card rule
# using fruState and fruStatus to decide whether the loop-card is normal
#
proc rple402 { action ruleId {rowName ""} {rowIndex 0} {matchList ""} } {
	switch $action {
		condition {
			ddl print debug " rple402 condition \n"

			set state [ getExternalRowValue $ruleId fruState $rowIndex ]
			set status [ getExternalRowValue $ruleId fruStatus $rowIndex ]

			set nodename [ getExternalRowValue $ruleId sunSmNodeName $rowName ]
			setRuleParm DYN $ruleId $rowName cur_node $nodename

			expr { ($state != "enabled") || ($status != "ready") }
		}

		init {
			ddl print debug " rple402 init \n"
			return ""
		}

		open {
			ddl print debug " rple402 open \n"

			set nodename [ getRuleParm DYN $ruleId $rowName cur_node ]
			set state [ getExternalRowValue $ruleId fruState $rowIndex ]
			set status [ getExternalRowValue $ruleId fruStatus $rowIndex ]

			set longmsg [ format [ getRuleMsg irple402longmsg ] "$nodename" "$state" "$status" ]

			if { $status == "fault" } {
				setRuleText $ruleId $rowName error $longmsg
				return error
			} else {
				setRuleText $ruleId $rowName warning $longmsg
				return warning
			}
		}

		continue {
			ddl print debug " rple402 continue \n"

			set nodename [ getRuleParm DYN $ruleId $rowName cur_node ]
			set state [ getExternalRowValue $ruleId fruState $rowIndex ]
			set status [ getExternalRowValue $ruleId fruStatus $rowIndex ]

			set longmsg [ format [ getRuleMsg irple402longmsg ] "$nodename" "$state" "$status" ]

			if { $status == "fault" } {
				setRuleText $ruleId $rowName error $longmsg
				return error
			} else {
				setRuleText $ruleId $rowName warning $longmsg
				return warning
			}
		}

		ack {
			return ""
		}

		fix {
			return ""
		}

		close {
			ddl print debug " rple402 close \n"
			return ok
		}
	}
}



#
# Rule 403
# fru/power-cooling-unit rule
# using fruState and fruStatus to decide whether the power-cooling-unit 
#   is normal
#
proc rple403 { action ruleId {rowName ""} {rowIndex 0} {matchList ""} } {
	switch $action {
		condition {
			ddl print debug " rple403 condition \n"

			set state [ getExternalRowValue $ruleId fruState $rowIndex ]
			set status [ getExternalRowValue $ruleId fruStatus $rowIndex ]

			set nodename [ getExternalRowValue $ruleId sunSmNodeName $rowName ]
			setRuleParm DYN $ruleId $rowName cur_node $nodename

			expr { ($state != "enabled") || ($status != "ready") }
		}

		init {
			ddl print debug " rple403 init \n"
			return ""
		}

		open {
			ddl print debug " rple403 open \n"

			set nodename [ getRuleParm DYN $ruleId $rowName cur_node ]
			set state [ getExternalRowValue $ruleId fruState $rowIndex ]
			set status [ getExternalRowValue $ruleId fruStatus $rowIndex ]

			set longmsg [ format [ getRuleMsg irple403longmsg ] "$nodename" "$state" "$status" ]

			if { $status == "fault" } {
				setRuleText $ruleId $rowName error $longmsg
				return error
			} else {
				setRuleText $ruleId $rowName warning $longmsg
				return warning
			}
		}

		continue {
			ddl print debug " rple403 continue \n"

			set nodename [ getRuleParm DYN $ruleId $rowName cur_node ]
			set state [ getExternalRowValue $ruleId fruState $rowIndex ]
			set status [ getExternalRowValue $ruleId fruStatus $rowIndex ]

			set longmsg [ format [ getRuleMsg irple403longmsg ] "$nodename" "$state" "$status" ]

			if { $status == "fault" } {
				setRuleText $ruleId $rowName error $longmsg
				return error
			} else {
				setRuleText $ruleId $rowName warning $longmsg
				return warning
			}
		}

		ack {
			return ""
		}

		fix {
			return ""
		}

		close {
			ddl print debug " rple403 close \n"
			return ok
		}
	}
}

#
# Rule 404
# system/basic-table/basic-entry/sysStatus rule
# if "sysStatus" not equal "ok" , it means there is something wrong
# with this t3 box.
#
proc rple404 { action ruleId {rowName ""} {rowIndex 0} {matchList ""} } {
        switch $action {
                condition {
                        set status [ getExternalRowValue $ruleId sysStatus $rowName ]
                        expr { ($status != "ok") }
                }
                init {
                        return ""
                }

                open {
                        set status [ getExternalRowValue $ruleId sysStatus $rowName ]
                        set longmsg [ format [ getRuleMsg irple404longmsg ] "$status" ]
                        if { $status != "ok" } {
                                setRuleText $ruleId $rowName warning $longmsg
                                return warning
                        }
                }

                continue {
                        set status [ getExternalRowValue $ruleId sysStatus $rowName ]
                        set longmsg [ format [ getRuleMsg irple404longmsg ] "$status" ]
                        if { $status != "ok" } {
                                setRuleText $ruleId $rowName warning $longmsg
                                return warning
                        }
                }

                ack {
                        return ""
                }

                fix {
                        return ""
                }

                close {
                        return ok
                }
        }
}
