ITRS-Group / monitor-ninja

Ninja is Now Just Awesome - a modern web GUI for Naemon
Other
32 stars 16 forks source link

Cannot set downtime to service #3

Open techadrian opened 7 years ago

techadrian commented 7 years ago

Hi Guys,

Been trying to implement ninja with merlin and naemon and got stuck at downtime setting for services : Selecting start time and endtime like this 2017-01-26 01:00:00 and 2017-01-27 01:00:00 I got the following error :

There was an error submitting your command to Ninja. ERROR: 2017-01-26 00:00:00 is not a valid date, please adjust it

Tried different formats, it does not work .....

Log states : Failed to submit command 'schedule_downtime' on (services) object 'hplj2605dn;PING' Output: 2017-01-26 01:00:00 is not a valid date, please adjust it

Any chance you can have a look at this ?

Thanks, Adrian

chelmertz commented 7 years ago

Hey @techadrian,

The label of the field is hardcoded as

Start time in the format: YYYY-MM-DD hh:mm:ss

which is incorrect because it does not take the configuration of the date format into account.

You want to double check the actual format you are using. The configuration value you are looking for is "date_format" inside of naemon.cfg. On an OP5 Monitor installation, this can be found through `grep date_format naemon.cfg.

On an OP5 Monitor installation, this should do it for you:

# grep date_format /opt/monitor/etc/naemon.cfg 
date_format=iso8601

If you are using Ninja/Naemon/Merlin on your own hand, you will find naemon.cfg in another path.

Once you got the configuration value, which in my example is iso8601, you can look for the expanded date format in this file: ninja/application/helpers/date.php. Here's a relevant link for you: https://github.com/op5/ninja/blob/eeae3cfeee1/application/helpers/date.php#L148-L160

techadrian commented 7 years ago

Hi chelmertz,

Thank you so much for pointing me to the right direction. I have analyzed the code and your response and date_format=iso8601 was in my naemon config, however, taking a closer look at this line of code : https://github.com/op5/ninja/blob/eeae3cfeee1/application/helpers/date.php#L138-L138 nagios.cfg si hardcoaded into code, this will not work in any case with naemon, as naemon uses naemon.cfg not nagios.cfg as main config file therefore search for date_format in nagios.cfg will always return false.

My fix was : change from nagios.cfg in naemon.cfg in date.php Dirty fix : symlink /etc/naemon/naemon.cfg to /etc/naemon/nagios.cfg

Do you think we can adjust the code to treat this exception?

Cheers, Adrian

chelmertz commented 7 years ago

Hi again Adrian,

Thanks for digging in! In OP5 Monitor (the product that we sell, that includes Ninja), we actually symlink nagios.cfg to naemon.cfg as one way to handle legacy installations. I don't think we have ever reflected on this particular issue from the OSS PoV, but I really think that we should abstract it away, so that you do not have to change parts of the code inside of the product.

I'm thinking that the date_format probably should reside in a Ninja configuration file instead (application/config/date.php or such). It may then differ to whatever is inside of nagios.cfg/naemon.cfg but at least it is coherent with the rest of Ninja, which I think is a good thing. What do you think about that?

techadrian commented 7 years ago

Hi Carl,

Moving date_format setting in ninja from a "complete dinamic" method by looking in nagios.cfg/naemon.cfg to a configuration like application/config/date.php would be too much in my opinion since we create a config file for only one value. If there would have been more values regarding date .....yeah.....that would work ...but using it only for date_format ....

The most easy way I see doing that is in https://github.com/op5/ninja/blob/eeae3cfeee1/application/helpers/date.php and add a default value. Something like ....if nagios.cfg or naemon.cfg cannot offer the value, use date_format=iso8601 by default. Doing that you keep the "dinamic" aspect and you also treat the exception in a few lines of code. If there is a incompatibility like a user has a naemon.cfg with date_format=us and ninja uses the default date_format=iso8601, you see that in the logs of naemon, that an incompatible date format is used. Using iso8601 also makes more sense with "Start time in the format: YYYY-MM-DD hh:mm:ss" that is hardcoaded into the interface: with iso8601 you enter the date in exactly the same format as interface shows you .

Hope that helps.

Cheers, Adrian