# Check parameters based on client's tag

**URL:** <https://discourse.sensu.io/t/check-parameters-based-on-clients-tag/666>\
**Category:** Sensu Classic (EOL)\
**Created:** [September 1, 2016, 9:41am UTC](https://discourse.sensu.io/t/check-parameters-based-on-clients-tag/666 "2016-09-01T09:41:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Volodymyr\_Linevych](https://avatars.discourse-cdn.com/v4/letter/v/f07891/32.png) [@Volodymyr\_Linevych](https://discourse.sensu.io/u/Volodymyr_Linevych)\
**Post date:** [September 1, 2016, 9:41am UTC](https://discourse.sensu.io/t/check-parameters-based-on-clients-tag/666/1 "2016-09-01T09:41:17Z")

</div>

Hello,

I wonder if it’s possible to manage client’s check parameters using client’s tags.

Example: two servers belong to different environments. Environment name is stored in client’s tag. Servers have the same role, which means the same subscription name. But for ‘prod’ i need to run checks more often or with different parameters than for ‘dev’.

As far as I can see, sensu check object does not have any conditionals or filtering properties.

At this moment I’ve implemented this logic using different subscriptions, for example ‘dev\_cassandra’ and ‘prod\_cassandra’,

and these subscriptions have different checks attached. But this approach causes a lot of code duplication if you have more than two environments.

Can I avoid having different subscriptions?

Thanks.

---

<div class="post-metadata">

**Author:** ![Moises\_Silva](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@Moises\_Silva](https://discourse.sensu.io/u/Moises_Silva)\
**Post date:** [September 1, 2016, 3:21pm UTC](https://discourse.sensu.io/t/check-parameters-based-on-clients-tag/666/2 "2016-09-01T15:21:00Z")

</div>

In my experience the only way to solve this is using configuration systems  
like Ansible or Salt to distribute your checks and use stand-alone checks  
(not server-scheduled checks), where the interval would be a template  
variable (e.g in ansible {{ cassandra\_check\_interval }} and that variable  
is set to different values depending on the environment.

> **···**
>
> On Thu, Sep 1, 2016 at 5:41 AM, Volodymyr Linevych \<vo.on3z@gmail.com\> wrote:
> 
> > Hello,
> > 
> > I wonder if it's possible to manage client's check parameters using  
> > client's tags.
> > 
> > Example: two servers belong to different environments. Environment name is  
> > stored in client's tag. Servers have the same role, which means the same  
> > subscription name. But for 'prod' i need to run checks more often or with  
> > different parameters than for 'dev'.
> > 
> > As far as I can see, sensu check object does not have any conditionals or  
> > filtering properties.
> > 
> > At this moment I've implemented this logic using different subscriptions,  
> > for example 'dev\_cassandra' and 'prod\_cassandra',  
> > and these subscriptions have different checks attached. But this approach  
> > causes a lot of code duplication if you have more than two environments.
> > 
> > Can I avoid having different subscriptions?

---

<div class="post-metadata">

**Author:** ![Caleb\_Hailey](https://avatars.discourse-cdn.com/v4/letter/c/8dc957/32.png) [@Caleb\_Hailey](https://discourse.sensu.io/u/Caleb_Hailey)\
**Post date:** [October 7, 2016, 4:35pm UTC](https://discourse.sensu.io/t/check-parameters-based-on-clients-tag/666/3 "2016-10-07T16:35:08Z")

</div>

Volodymyr,

Sensu provides a first-class primitive for this called “token substitution” and it is designed to solve the exact problems you are describing. See here: [https://sensuapp.org/docs/0.26/reference/checks.html#check-token-substitution](https://sensuapp.org/docs/0.26/reference/checks.html#check-token-substitution)

I hope this helps!

#monitoringlove

> **···**
>
> On Thursday, September 1, 2016 at 2:41:17 AM UTC-7, Volodymyr Linevych wrote:
> 
> > Hello,
> 
> > I wonder if it’s possible to manage client’s check parameters using client’s tags.
> 
> > 
> 
> > Example: two servers belong to different environments. Environment name is stored in client’s tag. Servers have the same role, which means the same subscription name. But for ‘prod’ i need to run checks more often or with different parameters than for ‘dev’.
> 
> > 
> 
> > As far as I can see, sensu check object does not have any conditionals or filtering properties.
> 
> > 
> 
> > At this moment I’ve implemented this logic using different subscriptions, for example ‘dev\_cassandra’ and ‘prod\_cassandra’,
> 
> > and these subscriptions have different checks attached. But this approach causes a lot of code duplication if you have more than two environments.
> 
> > 
> 
> > Can I avoid having different subscriptions?
> 
> > 
> 
> > Thanks.

---

<div class="post-metadata">

**Author:** ![Joel\_Smith1](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@Joel\_Smith1](https://discourse.sensu.io/u/Joel_Smith1)\
**Post date:** [October 12, 2016, 10:33am UTC](https://discourse.sensu.io/t/check-parameters-based-on-clients-tag/666/4 "2016-10-12T10:33:54Z")

</div>

Caleb, is it possible to use token substitution for handlers as well? The particular use I am thinking of is a definition for a mailer handler to go to particular teams for specific servers.

We could use a generic check, but in the client definition specify the support email handler for the specific team that manages the servers.

Eg, one mailer handler for internal servers, one mailer fordev servers, one mailer for live servers etc, but we have one set of standard checks that run for all of them.

Cheers,

Joel

> **···**
>
> On Friday, 7 October 2016 17:35:08 UTC+1, Caleb Hailey wrote:
> 
> > Volodymyr,
> 
> > Sensu provides a first-class primitive for this called “token substitution” and it is designed to solve the exact problems you are describing. See here: [https://sensuapp.org/docs/0.26/reference/checks.html#check-token-substitution](https://sensuapp.org/docs/0.26/reference/checks.html#check-token-substitution)
> 
> > 
> 
> > I hope this helps!
> 
> > 
> 
> > #monitoringlove
> > 
> > On Thursday, September 1, 2016 at 2:41:17 AM UTC-7, Volodymyr Linevych wrote:
> > 
> > > Hello,
> 
> > > I wonder if it’s possible to manage client’s check parameters using client’s tags.
> 
> > >
> 
> > > Example: two servers belong to different environments. Environment name is stored in client’s tag. Servers have the same role, which means the same subscription name. But for ‘prod’ i need to run checks more often or with different parameters than for ‘dev’.
> 
> > >
> 
> > > As far as I can see, sensu check object does not have any conditionals or filtering properties.
> 
> > >
> 
> > > At this moment I’ve implemented this logic using different subscriptions, for example ‘dev\_cassandra’ and ‘prod\_cassandra’,
> 
> > > and these subscriptions have different checks attached. But this approach causes a lot of code duplication if you have more than two environments.
> 
> > >
> 
> > > Can I avoid having different subscriptions?
> 
> > >
> 
> > > Thanks.

---

<div class="post-metadata">

**Author:** ![Smith\_Joel\_HEALTH\_AN](https://avatars.discourse-cdn.com/v4/letter/s/8797f3/32.png) [@Smith\_Joel\_HEALTH\_AN](https://discourse.sensu.io/u/Smith_Joel_HEALTH_AN)\
**Post date:** [January 18, 2017, 4:47pm UTC](https://discourse.sensu.io/t/check-parameters-based-on-clients-tag/666/5 "2017-01-18T16:47:20Z")

</div>

To answer my own question, yes it is possible to use token substitution for handlers. Thus I have a check which uses the handlers  
[handlers =\> [‘mailer’,‘:::team\_mailer|default:::’,‘graphite\_status’],](https://sensuapp.org/docs/0.26/reference/checks.html#check-token-substitution)

``

and uses the token ‘team\_mailer’ to refer to the mailer which has been defined on the server in question with some json like:

{  
“client”: {  
“team\_mailer”: “dev\_poc\_mailer”  
}  
}

``

If team\_mailer has not been defined, then it uses the handler ‘default’ instead.

> **···**
>
> On Wednesday, 12 October 2016 11:33:54 UTC+1, [joel....@nhs.net](mailto:joel....@nhs.net) wrote:
> 
> > Caleb, is it possible to use token substitution for handlers as well? The particular use I am thinking of is a definition for a mailer handler to go to particular teams for specific servers.
> 
> > We could use a generic check, but in the client definition specify the support email handler for the specific team that manages the servers.
> 
> > 
> 
> > Eg, one mailer handler for internal servers, one mailer fordev servers, one mailer for live servers etc, but we have one set of standard checks that run for all of them.
> 
> > 
> 
> > Cheers,
> 
> > 
> 
> > Joel
> > 
> > On Friday, 7 October 2016 17:35:08 UTC+1, Caleb Hailey wrote:
> > 
> > > Volodymyr,
> 
> > > Sensu provides a first-class primitive for this called “token substitution” and it is designed to solve the exact problems you are describing. See here: [https://sensuapp.org/docs/0.26/reference/checks.html#check-token-substitution](https://sensuapp.org/docs/0.26/reference/checks.html#check-token-substitution)
> 
> > >
> 
> > > I hope this helps!
> 
> > >
> 
> > > #monitoringlove
> > > 
> > > On Thursday, September 1, 2016 at 2:41:17 AM UTC-7, Volodymyr Linevych wrote:
> > > 
> > > > Hello,
> 
> > > > I wonder if it’s possible to manage client’s check parameters using client’s tags.
> 
> > > >
> 
> > > > Example: two servers belong to different environments. Environment name is stored in client’s tag. Servers have the same role, which means the same subscription name. But for ‘prod’ i need to run checks more often or with different parameters than for ‘dev’.
> 
> > > >
> 
> > > > As far as I can see, sensu check object does not have any conditionals or filtering properties.
> 
> > > >
> 
> > > > At this moment I’ve implemented this logic using different subscriptions, for example ‘dev\_cassandra’ and ‘prod\_cassandra’,
> 
> > > > and these subscriptions have different checks attached. But this approach causes a lot of code duplication if you have more than two environments.
> 
> > > >
> 
> > > > Can I avoid having different subscriptions?
> 
> > > >
> 
> > > > Thanks.

---

<div class="post-metadata">

**Author:** ![Caleb\_Hailey1](https://avatars.discourse-cdn.com/v4/letter/c/8797f3/32.png) [@Caleb\_Hailey1](https://discourse.sensu.io/u/Caleb_Hailey1)\
**Post date:** [January 18, 2017, 11:18pm UTC](https://discourse.sensu.io/t/check-parameters-based-on-clients-tag/666/6 "2017-01-18T23:18:49Z")

</div>

Joel,

Hi there! Good questions, and good job with your tests/findings. To provide a little clarification and/or context here, and potentially point you in a better direction, as of [Sensu Core version 0.24](https://sensuapp.org/docs/0.24/overview/changelog.html#core-v0-24-0) token substitution may be used in any check definition attribute (previously this was only allowed in the “command” attribute. While this may be useful for configuring event handlers, we do have a first-class feature for this called “Contact Routing” (Sensu Enterprise only). In your example use case (i.e. to send emails to different addresses based on the source of the check; e.g. development environment vs production environment), this is a first-class feature in Sensu Enterprise. See here for more information: [https://sensuapp.org/docs/0.26/enterprise/contact-routing.html](https://sensuapp.org/docs/0.26/enterprise/contact-routing.html) 🙂

I hope this helps. Let me know if you have any further questions.

Cheers,

> **···**
>
> On Wed, Jan 18, 2017 at 8:47 AM, [joel.smith1@hscic.gov.uk](mailto:joel.smith1@hscic.gov.uk) wrote:
> 
> > To answer my own question, yes it is possible to use token substitution for handlers. Thus I have a check which uses the handlers  
> > [handlers =\> [‘mailer’,‘:::team\_mailer|default:::’,‘graphite\_status’],](https://sensuapp.org/docs/0.26/reference/checks.html#check-token-substitution)
> 
> > ``
> 
> > and uses the token ‘team\_mailer’ to refer to the mailer which has been defined on the server in question with some json like:
> > 
> > {  
> > “client”: {  
> > “team\_mailer”: “dev\_poc\_mailer”  
> > }  
> > }
> 
> > ``
> 
> > If team\_mailer has not been defined, then it uses the handler ‘default’ instead.
> > 
> > On Wednesday, 12 October 2016 11:33:54 UTC+1, [joel....@nhs.net](mailto:joel....@nhs.net) wrote:
> > 
> > > Caleb, is it possible to use token substitution for handlers as well? The particular use I am thinking of is a definition for a mailer handler to go to particular teams for specific servers.
> 
> > > We could use a generic check, but in the client definition specify the support email handler for the specific team that manages the servers.
> 
> > >
> 
> > > Eg, one mailer handler for internal servers, one mailer fordev servers, one mailer for live servers etc, but we have one set of standard checks that run for all of them.
> 
> > >
> 
> > > Cheers,
> 
> > >
> 
> > > Joel
> > > 
> > > On Friday, 7 October 2016 17:35:08 UTC+1, Caleb Hailey wrote:
> > > 
> > > > Volodymyr,
> 
> > > > Sensu provides a first-class primitive for this called “token substitution” and it is designed to solve the exact problems you are describing. See here: [https://sensuapp.org/docs/0.26/reference/checks.html#check-token-substitution](https://sensuapp.org/docs/0.26/reference/checks.html#check-token-substitution)
> 
> > > >
> 
> > > > I hope this helps!
> 
> > > >
> 
> > > > #monitoringlove
> > > > 
> > > > On Thursday, September 1, 2016 at 2:41:17 AM UTC-7, Volodymyr Linevych wrote:
> > > > 
> > > > > Hello,
> 
> > > > > I wonder if it’s possible to manage client’s check parameters using client’s tags.
> 
> > > > >
> 
> > > > > Example: two servers belong to different environments. Environment name is stored in client’s tag. Servers have the same role, which means the same subscription name. But for ‘prod’ i need to run checks more often or with different parameters than for ‘dev’.
> 
> > > > >
> 
> > > > > As far as I can see, sensu check object does not have any conditionals or filtering properties.
> 
> > > > >
> 
> > > > > At this moment I’ve implemented this logic using different subscriptions, for example ‘dev\_cassandra’ and ‘prod\_cassandra’,
> 
> > > > > and these subscriptions have different checks attached. But this approach causes a lot of code duplication if you have more than two environments.
> 
> > > > >
> 
> > > > > Can I avoid having different subscriptions?
> 
> > > > >
> 
> > > > > Thanks.
> 
> –
> 
> **Caleb Hailey** | President  
> 503.209.4070 (Mobile) | [@sensu](http://twitter.com/sensu) | [https://sensuapp.org](https://sensuapp.org)

---

<div class="post-metadata">

**Author:** ![jspaleta](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.sensu.io/jspaleta/32/141_2.png) [@jspaleta](https://discourse.sensu.io/u/jspaleta)\
**Post date:** [November 22, 2018, 2:07am UTC](https://discourse.sensu.io/t/check-parameters-based-on-clients-tag/666/7 "2018-11-22T02:07:41Z")

</div>


