#!/usr/local/bin/tclsh8.4
#
package require sql
#
set  dbhost "localhost"
set  dbuser "root"
set  dbpwd  ""
set  dbname "netmon"
set  dbtable "nmclog"
#
fconfigure stdin -encoding koi8-r
set str [ gets stdin ]
#
set obj [ lindex $str 0 ]
set msg [join [ lrange $str 1 end ] ]
set cat info
if { [regexp "DBG" $msg   ]} { set cat debug  }
if { [regexp "UP" $msg    ]} { set cat normal }
if { [regexp "WARN" $msg  ]} { set cat warn   }
if { [regexp "ALERT" $msg ]} { set cat alert  }
if { [regexp "TRAP" $msg  ]} { set cat trap   }
if { [regexp "DOWN" $msg  ]} { set cat crit   }
#
set dbh [ sql connect $dbhost $dbuser $dbpwd ]
sql selectdb $dbh $dbname
# 
sql exec $dbh "INSERT INTO $dbtable SET logtime=NOW(), category='$cat', object='$obj', message='$msg' ;" 
#
sql disconnect $dbh
#
exit