On Sunday, March 20, 2016 at 8:43:12 AM UTC-5, Jelle Smet wrote:
I'm not sure what you think I suggested. I said the agent reports when it applies changes. This includes changes associated with exported (possibly by other nodes) resources.
The agent is not involved at all in exporting resources, nor even directly in collecting exported resources.
So let's say we have following applied to a host:
The value of "tags" is automatically looked up in Hiera.
Let' say that, someone alters the value of $tags in Hiera for a specific host.
The next time the manifest is applied to the host this will result into the "host_tags" value for that host changing and being updated in PuppetDB.
No. The next time the master builds a catalog for the target node, PuppetDB is updated with the new exported resource information. The exported resource is not included in that node's catalog unless it is also collected for that node, and if it is not in the catalog then it is not applied. The class you present does not, itself, specify that anything whatever is applied to any node, and it has the full effect it ever will have during catalog building, even if the catalogs into which it is included are never applied at all.
As far as I know, unless I overlook something (hence my question), puppet agent is not reporting anything about this change.
I might have misinterpreted your answers into thinking that puppet agent should report on that.
You appear to have a misunderstanding about the nature of exported resources, and what it means to apply a resource. Exported resources, like virtual resources, provide a means for decoupling resource declaration from including resources in catalogs. Unlike ordinary resources, neither virtual nor exported resources are automatically included in the catalog of the node for which they are declared. Exported resources differ from virtual resources in that once declared, exported resources can be included in any node's catalog, whereas virtual resources can be included only in the catalog of the node for which they were declared. That exported resource data are recorded in PuppetDB is an internal mechanism for implementing that resource sharing, not in any way an end goal, nor a public interface.
Getting back to your case, I'm not sure what a Monitor resource represents in terms of the state of the machine to which it is applied, but my guess at the moment is that it doesn't represent anything at all, that no node is collecting any of these exported resources (nor, therefore, applying them), and that their whole purpose is simply to inject data into PuppetDB.
If you are nowhere collecting and applying the resources you are exporting, then you are even farther out in the boonies than I thought.
charming :)
You may be able to make some variation on this scheme work, but you are using Puppet much differently than it was designed to be used.
What can I say?
- Puppet agent is not allowed to communicate directly with the restful API in any way.
Therefor a custom type making puppet agent interface directly with the API (the cleanest approach) is unfortunately not possible.
So, what are the options available on the table?
All necessary data to configure monitoring is available as exported resources. I don't think it's unreasonable to find a way to take advantage of this.
Puppet does not emit any notifications when exported resources change. It does emit notifications at various levels when changes are applied to a node. Ergo, if you want Puppet to emit notifications about changes to these data, the data have to be associated with resources that have persistent state reflective of the data, and those resources need to actually be applied to some node.
Moreover, since the states of those resources need to fully capture the data that may change in order to accurately report when changes occur, it follows that those resources can serve as an alternative to PuppetDB as a data source for your middleware. This is preferable to scraping the data from PuppetDB for the same reason that putting triggers into the DB is not an acceptable solution to your problem.
The family of approaches that looks practical to me involves using exported File (or Concat::Fragment) resources to record the data, and having the node on which your middleware runs collect (all of) them. You could use the agent's exit status to trigger your middleware, but I'd suggest instead setting the middleware up with a service interface (i.e. an initscript if you have SysV-style service management), that hooks the 'restart' command to compiles the data (if necessary) and dispatches it to the appropriate REST endpoint. Then configure the resources to notify that service.
The only caveat here is that changes will not be delivered to the REST endpoint until the middleware node performs a catalog run. That will involve more delay than you already have, but clearly you don't need changes to be signaled immediately, because you already wait for other nodes' catalog requests to cause PuppetDB to be updated. You can modulate that to some extent via the Puppet run intervals of the nodes involved.
By all means, you're free to disagree with this approach. Heck, I even disagree with this approach but it's what I have to deal with and have no control over.
But, whether this is good idea or not is not the question I'm seeking help/advice about.
I am not so much criticizing the approach as trying to determine where its boundaries are. And trying to teach you a bit about the Puppet details that impact the problem. One of the reasons you are having trouble is that you are trying to use Puppet in a way that it was not designed to support. Still, if your management is not prepared to listen if you tell them that the requirements and constraints they have laid down cannot all be satisfied simultaneously, then you might consider looking for a better job (even if it turns out that you can find an acceptable solution in this particular case).
I'm just trying to find a way getting notified when exported resources change and move on from there.
If that's your only alternative, and -- as we've already covered -- you must not use triggers, then you are out of luck. Puppet does not emit any notifications when exported resource data change. On the other hand, it does emit notifications when resource changes are applied to a node, whatever the type and origin of the resource. Changes to exported resource data are associated with applying resource changes, but the two are not directly coupled.
John