Precisely Speaking
February 08, 2012, 02:16:00 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: So what's news with you?  Tell us about it in "Getting To Know You"!
 
   Home   Help Calendar Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: U2 to syslog?  (Read 1506 times)
slestak
Uber-Pro
****
Posts: 69



« on: April 08, 2010, 09:21:29 AM »

Is it trivial to write to aix's syslog using the local facility from Unibasic?  I need this really badly, and have not seen a good method.  One of my friends mentioned writing my own Basic client that uses a socket, but wanted to see if anyone else had an idea on this before starting.
Logged
slestak
Uber-Pro
****
Posts: 69



« Reply #1 on: April 08, 2010, 09:22:33 AM »

I do have a mailing list post from a fellow who does it currently with a C program, but trying to see if it can be done from Unibasic.
Logged
Alex Copeland
Professional
***
Posts: 21


Artist's rendering


« Reply #2 on: April 08, 2010, 12:22:06 PM »

My first attempt at this would be to use the logger command from AIX.  Using logger assumes that you want to write to the log on the local machine.

If you want  a UniBasic program that can establish a connection to a local or remote syslog server and send log messages according to the syslog protocol (RFC  3164 ), that might be a little more involved, but it should be possible, I think.  I guess I am just more inclined to use tools that are at hand at the AIX level. 

Man page for logger:

logger Command

Purpose

       Makes entries in the system log.

Syntax

       logger [ -f File ] [ -i ] [ -p Priority ] [ -t Tag ] [ Message ]

Description

       The logger command provides an interface to the syslog subroutine, which writes entries to the
       system log. A Message variable can be specified on the command line, which is logged
       immediately, or a File variable is read and each line of the File variable is logged. If you
       specify no flags or variables, the logger command will wait for you to enter a message from
       standard input. The messages returned by the LOG_KERN facility cannot be logged by this command.

Flags

       -f File
            Logs the specified File variable. If the Message variable is specified, this flag is
            ignored.
       -i
            Logs the process ID of the logger process with each line.
       -p Priority
            Enters the message with the specified priority. The Priority parameter may be a number or a
            facility.level priority specifier.
       -t Tag
            Marks every line in the log with the specified Tag parameter.
       Message
            Indicates the message to log. If this variable is not specified, the logger command logs
            either standard input or the file specified with the -f File flag.

Examples
       1    To log a message indicating a system reboot, enter:

            logger System rebooted
       2    To log a message contained in the /tmp/msg1 file, enter:

            logger -f /tmp/msg1
       3    To log the daemon facility critical level messages, enter:

            logger -pdaemon.crit

Exit Status

       This command returns the following exit values:
       0
            Successful completion.
       >0
            An error occurred.

Files

       /usr/bin/logger

            Contains the logger command.
Logged
precisonline
President/Chief Technologist
Administrator
Rock Star
*****
Posts: 1524



WWW
« Reply #3 on: April 11, 2010, 03:11:47 PM »

Based on what Alex has posted here, that should be trivial to handle from a BASIC subroutine.

SUBROUTINE UPDATE.SYSLOG(MSG)
PCPERFORM 'logger "' : MSG : '"'
RETURN


Of course, this is all theoretical at this point - I haven't done it on a live system - but it might be worth the effort to type in these few characters.
Logged

-Kevin
Accidents "happen"; success, however, is planned and executed.
slestak
Uber-Pro
****
Posts: 69



« Reply #4 on: May 07, 2010, 01:06:27 PM »

I am picking this back up again.  I decided on a few things:

  • Forward U2 aix servers' syslog to a central syslog server
  • Write a syslog client in python that is specifically for applications my company has written (or modified)

The reason for not using logger directly, is I don't want to be limited to syslog's LOCAL0 to LOCAL7 for application logic.  I also have a desire/need to gain access to this data.

The python logger has a namespace arg that lets you create loggers with arbitrary dot delimited names so I can log oori.ptp.optio differently than oori.ptp.reportlab.

The python logger also has multiple output handlers and just provides so much flexibility.  This solution is almost in its entirety borrowed from this solution.

There is a cgi that will display the last 300 submissions in a browser and they are forwarded on from this web app to a central syslog server.

Screenshot
In the webpage, the critical error is flashing.

One of the last pieces to resolve is how to safely pass a string from Unibasic to the python (clogger.py) clear of any shell breaking chars.  I typically strip them out, but I would love a way to escape them and keep them in the output.  I know that I can use '\' to escape them, but I can always come up with a counter example of another way to break it.

i.e.
  1 PROGRAM CLOGGER.TEST.RIG
  2
  3
  4 MSG = 'Test Prelude OORI.CC malfunction'
  5 LVL = "CRITICAL"
  6 NS  = "prelude.oori.cc"
  7 CALL CLOGGER(DQUOTE(MSG),NS,LVL)


MSG can have embedded single, double, and possible ampersands. 

The routine CLOGGER is:
 
  1 SUBROUTINE CLOGGER(MSG,NS,LVL)
  2 *
  3 * Commerce Application Logger
  4 *
  5 PCPERFORM "clogger.py --msg " : MSG : " --namespace " : NS : " -l ": LVL
  6 RETURN


I was considering using base64 encoding, but that will greatly increase the length of MSG, and doesn't really solve the problem.

Thoughts?  I guess I am looking for an equivalent to the python Pickle module's functionality.


Logged
precisonline
President/Chief Technologist
Administrator
Rock Star
*****
Posts: 1524



WWW
« Reply #5 on: May 07, 2010, 02:11:34 PM »

Allow me to be the first to try to talk you out of base64 encoding this. Smiley

Unidata doesn't have any real URL encoding or any other type of encoding for quotes, double quotes or the like.  However, it's easy to create a simple replacement of characters that could break the shell command, like this:

(before line 5 of CLOGGER)

MSG = CHANGE(MSG,'"','\"')
MSG = CHANGE(MSG,"'","\'")
MSG = CHANGE(MSG,'&','\&')

...repeat for as many characters as you might need.
Logged

-Kevin
Accidents "happen"; success, however, is planned and executed.
slestak
Uber-Pro
****
Posts: 69



« Reply #6 on: May 07, 2010, 02:28:00 PM »

Yes, that looks like the path of least resistance. 

Is there an @-var or user exit that can tell me the program and line of the currently statement executing?  Basically, if I were to stop a program in the debugger and do a ? where you get the call stack.  That first entry is what I would like.
Logged
precisonline
President/Chief Technologist
Administrator
Rock Star
*****
Posts: 1524



WWW
« Reply #7 on: May 07, 2010, 03:19:15 PM »

On Unidata the entire call stack can be retrieved using SYSTEM(49).  I believe the first attribute (or maybe the last?) will have what you need.  Note that this has value marks in it as well.
Logged

-Kevin
Accidents "happen"; success, however, is planned and executed.
slestak
Uber-Pro
****
Posts: 69



« Reply #8 on: May 10, 2010, 09:13:36 AM »

system(49) works well.  I have it returning the 2nd to last item as the location and it works.  I exclude the last, because I dont want to record the syslog client as the location.

@ACCOUNT is acting weird.  I clearly see in TCL using WHERE that I am in the TEST account, however, @ACCOUNT reports that I am in the PRODUCTION account.  I am using udt61 on aix.
Logged
precisonline
President/Chief Technologist
Administrator
Rock Star
*****
Posts: 1524



WWW
« Reply #9 on: May 10, 2010, 09:33:23 AM »

Instead of @ACCOUNT, you might try @WHO.  See if that gives you any different/better results.
Logged

-Kevin
Accidents "happen"; success, however, is planned and executed.
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.7 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!