log_type=$1 
log_level=$2

section=""

op_logs=""
dia_logs=""
sen_logs=""


for i in `cat /nn/etc/DiaLogger.conf | sed -e 's/\;\(.\)*//g'` ; do
  echo $i |egrep \\\[\(.\)\*\.\(.\)*\\\] >/dev/null 2>&1 
  if [ $? = 0 ] ; then
    level=Diag
    section=`echo $i | sed -e 's/\[//g' | sed -e 's/\]//g'`
    echo $section | grep \\\. > /dev/null
    if [ $? -ne 0 ] ; then
      section=""
      continue
    fi   
    continue
  fi
  if [ "$section" = "" ] ; then
    continue
  fi
  echo $i | grep LogClass  > /dev/null
  if [ $? = 0 ] ; then
    level=`echo $i | sed -e 's/LogClass\(.\)*=\( \)*//g'`
    if [ "$level" = "Sens" ] ; then
      sen_logs="$sen_logs $section"
    fi
    if [ "$level" = "Oper" ] ; then
      op_logs="$op_logs $section"
    fi
  fi
done

pdr_log_files=`/nn/bin/pdrcmd dir nnulogging`

for i in `echo $pdr_log_files` ; do 
  echo $i | grep Sections: > /dev/null
  if [ $? = 0 ] ; then 
    in_section=true
    continue;
  fi
  echo $i | grep Entries: > /dev/null
  if [ $? = 0 ] ; then
    break;
  fi
  echo $op_logs $sen_logs | grep $i > /dev/null
  if [ $? = 0 ] ; then 
    continue; 
  fi
  dia_logs="$dia_logs $i"
done

logs_to_update=""
case $log_type in 
Sens) logs_to_update=$sen_logs;;
Diag) logs_to_update=$dia_logs ;;
Oper) logs_to_update=$op_logs ;;
*) echo "Invalid log type" ; exit 1 ;;
esac

for i in $logs_to_update ; do 
  /nn/bin/pdrcmd modify "nnulogging\\$i\\level" $log_level > /dev/null 2>&1
done
