Docker-Nagios icon indicating copy to clipboard operation
Docker-Nagios copied to clipboard

Populate /opt/nagiosgraph/[etc|var] if empty

Open JasonRivers opened this issue 7 years ago • 13 comments

Reported by @jtome

If one is mounting /opt/nagiosgraph/etc or /opt/nagiosgraph/var outside of the container, and the mounted directory is empty nagiosgraph fails to load, Files should be copied in place if the directory is empty.

JasonRivers avatar Oct 16 '17 09:10 JasonRivers

I think a simple solution to this is to make the owner of those directories nagios rather than root. Makes sense?

masterfuzz avatar Dec 20 '17 16:12 masterfuzz

Hi! I just stumbled upon this project and created the pull request https://github.com/JasonRivers/Docker-Nagios/pull/65 to fix the ownership of a mounted /opt/nagios/var.

HTH Thomas

cupracer avatar May 02 '18 09:05 cupracer

This happened again, because during docker build after building nagiosgraph the sources are deleted. During docker startup you check if nagiosgraph is installed and try to install it otherwise, but the source folder is missing now. Pull request #96 solves that.

fregge avatar May 21 '19 17:05 fregge

which files need to be copied ? can you give instructions ?

wpyung avatar Jun 04 '19 15:06 wpyung

can you update the docker image so I can use nagiosgraph out of the box ?

wpyung avatar Jun 04 '19 16:06 wpyung

@JasonRivers

I've finally got nagiosgraph working with the docker container after a couple of days head-scratching, but to do it I had to:

  1. Outside the container, edit .\etc\objects\templates.cfg correcting the path of the two entries:
  • action_url /nagios/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$' onMouseOver='showGraphPopup(this)' onMouseOut='hideGraphPopup()' rel='/nagios/cgi-bin/showgraph.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&period=day&rrdopts=-w+450+-j
  1. edit .\nagiosgraph\etc\nagiosgraph.conf correcting the three entries:
  • graphcgiurl = /nagios/cgi-bin
  • javascript = /nagios/nagiosgraph/nagiosgraph.js
  • stylesheet = /nagios/nagiosgraph/nagiosgraph.css

The above two not too bad as the files are outside the container, but I also needed

  1. edit /opt/nagios/share/ssi/common-header.ssi. To do this I changed the startup command of the container in my docker-compose so that it runs the following before /usr/local/bin/start_nagios:
  • /bin/sed -i -e "s/src="/nagiosgraph/nagiosgraph.js/src="/nagios/nagiosgraph/nagiosgraph.js/" /opt/nagios/share/ssi/common-header.ssi

I have to do it on each startup, otherwise the change is lost on container teardown/image update. Having done all of that lot, it now draws graphs on mouseover, loads the nagiosgraph.js without 404ing, and the graph pages work too.

HTH (thanks for your work on the docker container, much appreciated BTW)

Kolossi avatar Jun 04 '19 18:06 Kolossi

I can't do that as my /opt/nagiosgraph location just contains 2 empty folders: etc and var How do I populate them and what further steps should I take ? I am not a docker expert - just a user...

Here is my docker run script

docker run --name nagios4
--hostname rcapp04-nagios
-v /srv/docker/volumes/nagios/opt/etc:/opt/nagios/etc
-v /srv/docker/volumes/nagios/opt/var:/opt/nagios/var
-v /srv/docker/volumes/Custom-Nagios-Plugins:/opt/Custom-Nagios-Plugins
-v /srv/docker/volumes/nagios/opt/nagiosgraph/var:/opt/nagiosgraph/var
-v /srv/docker/volumes/nagios/opt/nagiosgraph/etc:/opt/nagiosgraph/etc
-v /etc/timezone:/etc/timezone:ro
-v /etc/localtime:/etc/localtime:ro
-d --restart unless-stopped
-p 0.0.0.0:8099:80 jasonrivers/nagios:latest

here is what I see from docker exec -it nagios4 /bin/bash

root@rcapp04-nagios:/# ls / bin dev home lib64 mnt orig root sbin sys usr boot etc lib media opt proc run srv tmp var

root@rcapp04-nagios:/# ls /opt Custom-Nagios-Plugins JR-Nagios-Plugins nagios nagiosgraph JE-Nagios-Plugins WL-Nagios-Plugins nagios-mssql

root@rcapp04-nagios:/# ls -R /opt/nagiosgraph /opt/nagiosgraph: etc var

/opt/nagiosgraph/etc:

/opt/nagiosgraph/var:

wpyung avatar Jun 05 '19 10:06 wpyung

@wpyung

Before you start, you need to drop mounting your external versions of /opt/nagiosgraph/etc and ./var, and mount your /srv/docker/volumes/nagios/opt/nagiosgraph somewhere else in the docker filesystem - e.g. /opt/nagiosgraph/mytmp. Then you can copy the docker image versions of ./etc and ./var out to your external filesystem.

Having done that, put the /opt/nagiosgraph/etc and /opt/nagiosgraph/var mounts back in and you should be good. This approach likely also needed for /opt/nagios/etc and /opt/nagios/var dirs too.

Kolossi avatar Jun 05 '19 10:06 Kolossi

great that did it with no other changes required /opt/Nagios is OK Thanks for your help so far...

I see 4 graphs. Yearly and Monthly have data, weekly and daily are blank. Is there something I have to tweak ? Or is it just a question of waiting

image

wpyung avatar Jun 05 '19 11:06 wpyung

Yay, glad it's working. There is one reading in the daily data (min=max=avg=curr), and you can just see the pixels on the RHS of the graph, so I think it's just a case of waiting.

Kolossi avatar Jun 05 '19 12:06 Kolossi

Hi, how did you mount back the volumes ? Because it seems like you can't mount volumes in a running container.. Please let me know

duckmysick01 avatar Mar 23 '22 08:03 duckmysick01

you just need to stop the container to do the mounts and unmounts, then restart it

wpyung avatar Mar 28 '22 07:03 wpyung

thanks

duckmysick01 avatar Apr 04 '22 07:04 duckmysick01