#!/bin/sh

processCDM570()
{
	echo processCDM570 function called >> /tmp/trap.log
	min=0
	max=0
  	#unit alarms
  	if [[ $oid == *1.3.1.1.0 ]]
  	then
  		min=1
  		max=15
  	fi
  	#tx alarms
  	if [[ $oid == *1.3.1.2.0 ]]
  	then
  		min=16
  		max=30
  	fi
  	#rx alarms
  	if [[ $oid == *1.3.1.3.0 ]]
  	then
  		min=31
  		max=45
  	fi

	if [ $val != "0" ]
	then
		#received new active alarm
		status=$(($min - 1 + $val))
	else
		#clear all alarms in min-max range
		status=0
	fi

	echo "select status, raised from Alarms where time = 0 and id = $id and status >= $min and status <= $max" \
		| mysql -usatis -psatis satis | grep -v raised | while read current_status current_raised
	do
		if [ "$status" == "0" ]
		then
			if [ "$current_raised" != "0" ]
			then
				insertAlarm $id $current_status 0
			fi
		else
			if [ "$current_raised" != "0" -a "$current_status" != "$status" ]
			then
				insertAlarm $id $current_status 0
			fi
		fi 
	done
	
	if [ "$status" != "0" ]
	then
		insertAlarm $id $status 1
	fi
} 

