-
-
Notifications
You must be signed in to change notification settings - Fork 407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Develop a pluggable logging API for Cacti to be able to log to alternate logging formats #5852
Comments
Thoughts about capabilities and formatsThe local logging must be unified
Considerations for configuration
Additional considerations:
log items/identifiersMinimum/mandatory set of information (identifiers)
Optional items (where applicable / during debugging)
Collection of possible (sub)sections:
support for output plug-insThe logging function should act as a hub for plug-ins that allow logging to not only a local file but also other destinations.
Thoughts about implementation phasesprepare the refactoring
reforming the logging concept
|
Whoever has ideas that need to be considered, please speak up! :) |
Subsection also for plug-in modules. It could be useful if I can filter messages only from a specific plugin, for example if I have debug enabled for it |
I hope to provide some comments next week. |
All, I've had a detailed conversation with @Linegod whose day job has everything to do with logging. Let me summarize here where we aligned. I will do this in code form as well as descriptive.
Now for my position. One way or another, the cacti.log file will remain the same, emulating the tags already defined regardless of the input type. We will discuss more tomorrow in our call. Larry |
We could store the plugins in a table as a name value pair of course, with a pre-defined JSON structure holding the important columns as above. This is pretty popular these days with people using name value stores such as reddis, but why not the Cacti settings table (just kidding), we will create it it's own table format and cache the document at the session level. It'll be stored in JSON. I guess the 'template' could be stored on disk. Let's discuss. |
So, I would propose something like the following as a default object structure, it can of course be increased by caller: $message = array(
'timestamp' => unix timestamp in integer or millisecond format (optional),
'message' => text,
'level' => LOW|MED|HIGH|DEBUG|...,
'hostname' => either Cacti or the device I'm open,
'app' => third parameter on the current logging facility,
'metadata' => array(
'thing' => $value,
...
)
); Then, as additional optional metadata that we know of today that can be reverse engineered into the object structure and currently captured in the $regex_array = array(
1 => array('name' => 'DS', 'regex' => '( DS\[)([, \d]+)(\])', 'func' => 'text_regex_datasource'),
2 => array('name' => 'DQ', 'regex' => '( DQ\[)([, \d]+)(\])', 'func' => 'text_regex_dataquery'),
3 => array('name' => 'Device', 'regex' => '( Device\[)([, \d]+)(\])', 'func' => 'text_regex_device'),
4 => array('name' => 'Poller', 'regex' => '( Poller\[)([, \d]+)(\])', 'func' => 'text_regex_poller'),
5 => array('name' => 'RRA', 'regex' => "([_\/])(\d+)(\.rrd')", 'func' => 'text_regex_rra'),
6 => array('name' => 'GT', 'regex' => '( GT\[)([, \d]+)(\])', 'func' => 'text_regex_graphtemplates'),
7 => array('name' => 'Graph', 'regex' => '( Graph\[)([, \d]+)(\])', 'func' => 'text_regex_graphs'),
8 => array('name' => 'Graphs', 'regex' => '( Graphs\[)([, \d]+)(\])', 'func' => 'text_regex_graphs'),
9 => array('name' => 'User', 'regex' => '( User\[)([, \d]+)(\])', 'func' => 'text_regex_users'),
10 => array('name' => 'User', 'regex' => '( Users\[)([, \d]+)(\])', 'func' => 'text_regex_users'),
11 => array('name' => 'Rule', 'regex' => '( Rule\[)([, \d]+)(\])', 'func' => 'text_regex_rule'),
); I noticed a few things missing from the 'standard' like Site[], Location[], Thold[], Alert[] for example. These would all be captured under metadata. At least that is where my head is at. If we follow that structure, we can provide a human readable message in the cacti.log file, as well as JSON to any of the feed types. |
@Linegod please jump in. Is this kind of where your head was too? |
@TheWitness - yes, that's pretty much what I was thinking. A little bit of digging lead me this though: https://github.com/Seldaek/monolog Most of the heavy lifting could be accomplished just by using monolog |
Oh, look 'composer'. Last time, that did not go very well. No worries. |
There are 4 other vendor libraries using composer, so I didn't think it would be an issue.
And monolog is PSR-3 compliant, so it adheres to the PHP logging standards. And the PHP logging standards are RFC5424 compliant, so they adhere to the syslog standard. |
Hmm thinking again about Larry's idea of the hostname parameter, i come to a different conclusion ... 'hostname' => either Cacti or the device I'm open, I believe to match the standard, it should rather be the name of the originating server that generates the log line. It's similar to for example firewall logs, where we have the FW itself writing the log line, which is also reflected as the hostname part in the 5424 syslog. But it might also contain a hostname of a device that connects across it, and that is logged in the (more or less) structured part of the log message. And this metadata part: BTW i think we should start with some meta-code, getting all this structured part in order before we fill it with life, providing the actual code that processes everything. Comments? |
Comment on the timestamp: If we can rely on the precision originating time stamp, where logs are produced in a given logical sequence, this helps in the re-ordering in such cases. |
Regarding Graphs and Users: I think we can handle those always as an array. Either it contains 1 element or it contains more, and it is easier to have it as an array in all cases, that makes the handling easier. So we can say this:
would become this single line:
Same here:
(adapt the numbers in front as necessary) |
Another comment or question on this. Should we not log Tina table first and then have a proxy forward so as to not impact Cacti if the log receiver is down? |
Or better yet just let our sis log D do the forwarding for us. We just have to write to the json format in an alternate location and let it do all work. For those on Windows I guess well I care maybe? I don't know... |
Logging into a DB in principle has the same constraint .. if the target DB is down -> fails. This brings me to something that we need to consider: And if we let syslog do the stuff, then Since caching on failure is generally a very wise idea, I suggest to keep it simple: |
We should handle like our syslog integration. Be able to exclude by string match or level. One thing at a time though. Packaging this week. |
Okay, I'm winding down on projects. So, please let me know what you think.
If we do this, I can have it finished (first pass), in just a few hours. @bernisys @Linegod @netniV @xmacan @browniebraun @seanmancini, please chime in. |
Sounds like a plan |
@Linegod , RFC5424 for structured data is not quite JSON. Are we okay just running with JSON though with the zulu timestamp? |
@TheWitness: Sounds okay so far, i am just not too comfortable with that part: "cacti_log() will take mixed input either array or string" I would create a new logging function (func-name TBD) that takes only JSON-like objects (hash-arrays internally), and then point the old func to the new one and in the code replace the logging functions everywhere and review the calls and their contents at the same time. This offers higher processing speed in the core, because we don't need to distinguish, what kind of object we get, when the func is called. Regarding the timestamp: That (as well as all further parts of the given data) would be formatted only when the log is actually written to a destination, so internally we can keep a simple number-based time format, maybe epoch + millis or something like that. What ever php offers and what ever is best to process without too much overhead. And i believe the current cacti.log can (should) be kept, too, as it is more human-readable than JSON. It's just another internal output plug-in, and the formatting of the lines is necessary anyway, when we want to write the lines to syslog, it's a rather similar format. So why not "re-use" that and write the good old cacti.log that the users already know. Avoids some confusion i would say. Comments please :) |
Feature Request
Is your feature request related to a problem? Please describe
Support extensible logging to Splunk, Kafka, Elastic, etc.
Describe the solution you'd like
We need to determine the minimum logging attributes that are required to encompass these various logging solutions and then define the JSON, XML, etc. structures that are the minimum to perform such logging, and finally an API and class library that extends the output format using a pluggable and extensible output class function.
Describe alternatives you've considered
Continuing one size fit's all logging format.
Additional context
This is an R&D project that should deliver a report on what should happen vs. simply coding an enhancement. So, it's a call for a design document.
The text was updated successfully, but these errors were encountered: