# # $Id: nbspfilter.rc-ex,v 1.4 2005/09/04 13:33:49 nieves Exp $ # # This is not a working file. It is a documentation file with some # background information and a few sample rule/action instructions # to illustrate the syntax and possible uses of a real nbspfilter.rc file. # # - Background information # # The main script script is written in tcl, so this file must be written # in that same language. This file is ``sourced'' by the main script by # an instruction # # source /usr/local/etc/nbsp/nbspfilter.rc # # At the time this files is sourced, the following variables are visible # and can be used in this script: # # # seq, type, cat, code (see below) # fpath = full path of the file # fname = basename of the file # body = first 512 (configurable in nbspfilter.conf) bytes of the file # station, wmoid, awips, nawips # # The first four, refer to the sbn sequence number, type, category and # code of the file, as classified by the noaaport broadcast system. They are # included for completeness in case they are needed for some particular # purpose, but we will not use them. # # The last four are the keywords extracted from the first and second # lines of the file. For example, a file that has been saved as # # /var/noaaport/nbsp/spool/TJSJ/tjsj_wgca82-flssju.453765 # # which contains # # WGCA82 TJSJ 022135 # FLSSJU # # in the first two lines # # then # $fpath = /var/noaaport/nbsp/spool/TJSJ/tjsj_wgca82-flssju.453765 # $fname = tjsj_wgca82-flssju # $station = tjsj # $wmoid = wgca82 # $awips = flssju # $nawips = "" # # A different example is a file saved as # # /var/noaaport/nbsp/spool/KNES/knes_zega98+grib.769436 # # The first line of this file has a standard wmo header but the second one # has the word GRIB followed by binary data: # # ZEGA98 KNES 200357 # GRIB ... # # In this case, the variable $awips is "", $nawips is set to "grib": # # $fpath = /var/noaaport/nbsp/spool/KNES/knes_zega98+grib.769436 # $fname = knes_zega98+grib # $station = knes # $wmoid = zega98 # $awips = "" # $nawips = grib # # In general, the $fname variable (the root file name) is of the form # # ${station}_${wmoid}-${awips} # # when there is an awips line, or # # ${station}_${wmoid}+${nawips} # # otherwise (a minus or a plus sign separating the last component, # respectively). For some files both $awips and $nawips are ""; # e.g., # /var/noaaport/nbsp/spool/KNES/knes_tige05.9435678 # # - Examples # # To save all messages containing the word URGENT in a directory # "/var/noaaport/data/URGENT" # if {[regexp {URGENT} $body]} { exec cat $fpath > /var/noaaport/data/URGENT/$fname; return; } # To email all such messages to nieves@cariberesearch.com, with the subject # URGENT # if {[regexp {URGENT} $body]} { filter_pipe $fpath "mail -s URGENT nieves@cariberesearch.com"; return; } # The same thing, but with the "From:" header as nbsp@noaaport.net # # if {[regexp {URGENT} $body]} { filter_sendmail "nbsp@noaaport.net" "nieves@cariberesearch.com" URGENT $fpath; return; } # Instead of sending all those messages, to restrict them only to those # coming from the TJSJ station # if {[regexp {URGENT} $body] && [regexp {tjsj} $station]} { filter_sendmail "nbsp@noaaport.net" "nieves@cariberesearch.com" "URGENT TJSJ" $fpath; return; } # The regular expression argument to the regexp function can be # much more complicated. For example, this will send by email almost # all the weather text bulletins from TJSJ: # if {[regexp {^tjsj_(f[glnopxz]ca[457]2)|(a[sw]ca[468]2)|(c[dsx]ca[456]2)|(w[gh]ca[578]2)} $fname]} { filter_sendmail "nbsp@noaaport.net" "nieves" "URGENT $wmoid" $fpath return; } # This will write a one line entry in a logfile, for each file received # set rcvtime [clock format [clock seconds]]; exec echo $fname $rcvtime > /var/noaaport/list.log; # Note that the keyword ``return'' prevents processing subsequent rules # when a rule is found to match. If that keyword is omitted then # the subsequent rules are processed as well (until a rule with the ``return'' # keyword matches). # For example, these will save all the # URGENT files _and_ also email the files from TJSJ # if {[regexp {URGENT} $body]} { exec cat $fpath > /var/noaaport/data/URGENT/$fname; } if {[regexp {tjtj} $station]} { filter_sendmail nbsp@noaaport.net nieves $wmoid $fpath return; } # # If the return keyword were added in the first rule, then the # URGENT files from TJSJ would not reach the second rule and would # not be emailed. # The next rule will catch and email the administrative messages # to the user "noaaportadmin" # if {[regexp {^(admn[0-68]|admn9[^9]|admn7[^5]|noxx|nous[^46789]|nous9[^7])} $wmoid] && [regexp {(kwno|kwbc|kncf)_nous[4678]} $fname]} { filter_sendmail nbsp@noaaport.net noaaportadmin ADM $fpath; return; }