- I've got some servers (www, etc)
- I've got a monitoring system
- If a machine has to be apache monitored it needs some files to be installed.
So I've got a apache
module (which installs Apache) and I'm writing a monitoring
module. This monitoring
module will copy the needed files, only if the apache package is installed (or if the apache module is defined, or something like that). Same for the mysql package, etc.
Is the above design a good idea? What would be the best way for this kind of dependency?
In your apache class you could define a variable, that you use in a test to see if you should deliver your monitoring file or not.
You need either virtual resources or custom facts. If the configuration of one host will change the configuration of another, then you need exported resources. I have all these things, actually. Here's a sampling.
Virtual Resources
On the Monitoring class:
On the Apache class:
Custom Facts
Declare a fact like this, and put it in the appropriate place (see link above):
On the Monitoring class, use:
Exported Resources
On the Apache class, included in the Apache server:
On the Monitoring class, included in the Monitoring server:
In your extdata, create a variable that defines whether or not a server needs to be monitored. Here's an example of enabling monitoring by default and disabling it for a specific server.
extdata/common.csv
extdata/ephemeral.example.com.csv
In your class for each service, lookup whether monitoring is enabled. If it is, include the class responsible for monitoring that service. This could look something like
Update: When I first read your question, I thought you were asking for a way to enable monitoring on some but not all of your Apache servers. If you want to monitor all of them, you don't even need to bother with extlookup. Just split up your monitoring class into service-specific ones and include them in the class for the service.
Why don't just
require => Package['apache']
on resources in monitoring module? If there'sapache
andmonitoring
classes added to node, files that depends on apache would be installed iff it's installed succesfully. If it does not (e.g. package failed to install, or apache module is not added to node, monitoring class would just fail).Or if you don't want it to fail, you could use something like following: