ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » General IBM MQ Support » Python Host/node name in Logging file name

Post new topic  Reply to topic
 Python Host/node name in Logging file name « View previous topic :: View next topic » 
Author Message
bobbee
PostPosted: Tue Jul 19, 2022 7:43 am    Post subject: Python Host/node name in Logging file name Reply with quote

Knight

Joined: 20 Sep 2001
Posts: 541
Location: Tampa

I am writing an MQ Configuration Check script. I would like to add the host/node name to the file name. I looked at alot of Google search results on the subject. No one seems to use a logging.conf file. I tried implementing 'some' of what looked like what would fit. No luck. Anyone? Here is the logging.conf file. As a last resort I can add the host/node name to the message.

Code:
[loggers]
keys=root,MQHardening

[handlers]
keys=fileHandler

[formatters]
keys=MQHardening

[logger_root]
level=DEBUG
handlers=fileHandler

[logger_MQHardening]
level=DEBUG
handlers=fileHandler
qualname=MQHardening
propagate=0

[handler_fileHandler]
class=FileHandler
level=DEBUG
formatter=MQHardening
args=(__import__("datetime").datetime.now().strftime('/var/mqm/hardening/MQHardening_%%Y-%%m-%%d_%%H-%%M-%%S.log'), 'a')
####### args=('MQHardening.log', 'w')

[formatter_MQHardening]
format=%(asctime)s - %(levelname)s - %(message)s
Back to top
View user's profile Send private message Send e-mail AIM Address
gbaddeley
PostPosted: Tue Jul 19, 2022 3:37 pm    Post subject: Reply with quote

Jedi

Joined: 25 Mar 2003
Posts: 2494
Location: Melbourne, Australia

/var/mqm/hardening ? Is this a local MQ hardening / checking solution at your company ? It's not part of the MQ product, and shouldn't be in /var/mqm, as it may interfere with the IBM MQ installation or configuration.
_________________
Glenn
Back to top
View user's profile Send private message
hughson
PostPosted: Tue Jul 19, 2022 10:11 pm    Post subject: Reply with quote

Padawan

Joined: 09 May 2013
Posts: 1914
Location: Bay of Plenty, New Zealand

Your question is unclear. Are you asking how to obtain the current host/node name (in order to put them as part of a file name) in Python?

Cheers,
Morag
_________________
Morag Hughson @MoragHughson
IBM MQ Technical Education Specialist
Get your IBM MQ training here!
MQGem Software
Back to top
View user's profile Send private message Visit poster's website
bobbee
PostPosted: Wed Jul 20, 2022 3:13 am    Post subject: Reply with quote

Knight

Joined: 20 Sep 2001
Posts: 541
Location: Tampa

I can get the Server/Node name. That is easy. Getting it into the name of the log file..........well.

I went the logging.conf file route. All the examples I see are setting the logging variables programmatically. I was looking for an example, but I feel I may have to change the code to do it programmatically.
Back to top
View user's profile Send private message Send e-mail AIM Address
bobbee
PostPosted: Wed Jul 20, 2022 3:16 am    Post subject: Reply with quote

Knight

Joined: 20 Sep 2001
Posts: 541
Location: Tampa

@gbaddeley,
Customer.
That was on a test AIX box I provisioned inside my own company. When I moved it to the customers server the location changed to something more appropriate. Thanks for Policing.
Back to top
View user's profile Send private message Send e-mail AIM Address
hughson
PostPosted: Wed Jul 20, 2022 3:30 am    Post subject: Reply with quote

Padawan

Joined: 09 May 2013
Posts: 1914
Location: Bay of Plenty, New Zealand

Do you mean that you are trying to use this: https://docs.python.org/3/library/logging.config.html

?

I use the same logging but have never used the config file, just called logging.basicConfig - I guess I didn't need whatever complexity you are after.

Suggest Stackoverflow might be a better forum for your question than here?

Cheers,
Morag
_________________
Morag Hughson @MoragHughson
IBM MQ Technical Education Specialist
Get your IBM MQ training here!
MQGem Software
Back to top
View user's profile Send private message Visit poster's website
bobbee
PostPosted: Wed Jul 20, 2022 3:39 am    Post subject: Reply with quote

Knight

Joined: 20 Sep 2001
Posts: 541
Location: Tampa

Yes, EXACTLY!!

There was some education and video stuff on a UNIX forum for logging.conf . I found the creators name and sent him an email with the same question. But, that is a crap shoot.

When I have the time, I guess my route is to change the code. In the long run it will make changes easier. I can move the important stuff from the logging.conf file up to my main properties file and stilll have control.

You know what is going to happen? When I find the time, change it, get it tested and working, the guy will answer me..................and it will be simple!!!! LOL

They are going to run this script on all their QMGRS to get them in internal compliance and keep them that way. Not really Hardening, but that is what they want to name them. If they start uploading these to a repository I wanted the server name in the file name to distinguish them apart.
Back to top
View user's profile Send private message Send e-mail AIM Address
gbaddeley
PostPosted: Wed Jul 20, 2022 4:12 pm    Post subject: Reply with quote

Jedi

Joined: 25 Mar 2003
Posts: 2494
Location: Melbourne, Australia

Code:
args=(__import__("datetime").datetime.now().strftime('/var/mqm/hardening/MQHardening_%%Y-%%m-%%d_%%H-%%M-%%S.log'), 'a')

Does this actually work, to include date time in the log file name?
args calls eval. Can eval be used to build up a formatted string with two { } expressions, containing code like strftime('%%Y-%%m-%%d_%%H-%%M-%%S), and os.environ['HOSTNAME'] ?
Sorry, I'm not an experienced python programmer, and haven't tried anything like this in eval.
_________________
Glenn
Back to top
View user's profile Send private message
bobbee
PostPosted: Thu Jul 21, 2022 3:16 am    Post subject: Reply with quote

Knight

Joined: 20 Sep 2001
Posts: 541
Location: Tampa

It has been working from the very start. This is the name of the file in my log directory:

MQHardening_2022-07-05_07-56-16.log

If you dig down into the logger doc. There are one or two things that are supported in naming the logger file.
Back to top
View user's profile Send private message Send e-mail AIM Address
gbaddeley
PostPosted: Thu Jul 21, 2022 3:17 pm    Post subject: Reply with quote

Jedi

Joined: 25 Mar 2003
Posts: 2494
Location: Melbourne, Australia

bobbee wrote:
If you dig down into the logger doc.

Good luck. Sorry, I don't have time to pursue this any further atm.
_________________
Glenn
Back to top
View user's profile Send private message
bobbee
PostPosted: Fri Jul 22, 2022 3:18 am    Post subject: Reply with quote

Knight

Joined: 20 Sep 2001
Posts: 541
Location: Tampa

no problem, just did my 1/2 year review and under skill put down, 'Became proficient in Python Pymqi, LOL
Back to top
View user's profile Send private message Send e-mail AIM Address
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » General IBM MQ Support » Python Host/node name in Logging file name
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.