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.


  1. # SysLog.tcl -- Send script errors to Router syslog, new lines removed
  2. # Copyright (C) 2009 Nigel Franklin
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License,
  7. # or any later version.
  8.  
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see http://www.gnu.org/licenses/
  16. #
  17. #
  18. # Description :
  19. # Sends a list, split into lines, or a string to the Router Syslog,
  20. # removes new lines and three or more consecutive white spaces from lists.
  21. #
  22. #
  23. # Revision # : 1.0
  24. # Last Revised : May 25, 2009
  25. # Last Revised by : Nigel Franklin
  26. # Author : Nigel Franklin, www.nigelfranklin.co.uk
  27. # Router Requirements :
  28. #
  29. # Cisco Products tested : 1801
  30. # Cisco IOS Versions tested : 12.4(11)XJ4
  31. #
  32. # Register the package
  33. package provide SysLog 1.0
  34. package require Tcl 8.3
  35.  
  36. # Create the namespace
  37. namespace eval ::SysLog:: {
  38. # Import names from 'required' package if used in this package
  39. #namespace import ::Tcl::*
  40. # Export commands
  41. namespace export logList
  42. namespace export logStr
  43. # Set up state
  44. # This is a command pipeline to the router syslog
  45. variable Syslog
  46. }
  47.  
  48. proc ::SysLog::logList {ScriptName level event List} {
  49. regsub -all {\r|\n|\s{3,}} $List " " List
  50. set Syslog [open "syslog: " w+]
  51. foreach Entry $List {
  52. puts $Syslog "%$ScriptName-$level-$event: $Entry"
  53. flush $Syslog
  54. }
  55. close $Syslog
  56. return
  57. }
  58.  
  59. proc ::SysLog::logStr {ScriptName level event Str} {
  60. set Syslog [open "syslog: " w+]
  61. puts $Syslog "%$ScriptName-$level-$event: $Str"
  62. close $Syslog
  63. return
  64. }
  65.  
  66. # ------------------ END OF FILE ------------------