Sends a list logList, split into lines, or a string logStr to the Router Syslog, removes new lines and three or more consecutive white spaces from lists.
- # SysLog.tcl -- Send script errors to Router syslog, new lines removed
- # Copyright (C) 2009 Nigel Franklin
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License,
- # or any later version.
-
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see http://www.gnu.org/licenses/
- #
- #
- # Description :
- # Sends a list, split into lines, or a string to the Router Syslog,
- # removes new lines and three or more consecutive white spaces from lists.
- #
- #
- # Revision # : 1.0
- # Last Revised : May 25, 2009
- # Last Revised by : Nigel Franklin
- # Author : Nigel Franklin, www.nigelfranklin.co.uk
- # Router Requirements :
- #
- # Cisco Products tested : 1801
- # Cisco IOS Versions tested : 12.4(11)XJ4
- #
- # Register the package
- package provide SysLog 1.0
- package require Tcl 8.3
-
- # Create the namespace
- namespace eval ::SysLog:: {
- # Import names from 'required' package if used in this package
- #namespace import ::Tcl::*
-
- # Export commands
- namespace export logList
- namespace export logStr
-
- # Set up state
- # This is a command pipeline to the router syslog
- variable Syslog
- }
-
- proc ::SysLog::logList {ScriptName level event List} {
- regsub -all {\r|\n|\s{3,}} $List " " List
- set Syslog [open "syslog: " w+]
- foreach Entry $List {
- puts $Syslog "%$ScriptName-$level-$event: $Entry"
- flush $Syslog
- }
- close $Syslog
- return
- }
-
- proc ::SysLog::logStr {ScriptName level event Str} {
- set Syslog [open "syslog: " w+]
- puts $Syslog "%$ScriptName-$level-$event: $Str"
- close $Syslog
- return
- }
-
- # ------------------ END OF FILE ------------------