# X-pack license email triggering

**URL:** <https://discuss.elastic.co/t/x-pack-license-email-triggering/97849>\
**Category:** Elasticsearch\
**Created:** [August 22, 2017, 5:23am UTC](https://discuss.elastic.co/t/x-pack-license-email-triggering/97849 "2017-08-22T05:23:27Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dibyakanta](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@Dibyakanta](https://discuss.elastic.co/u/Dibyakanta)\
**Post date:** [August 22, 2017, 5:23am UTC](https://discuss.elastic.co/t/x-pack-license-email-triggering/97849/1 "2017-08-22T05:23:27Z")

</div>

Continuing the discussion from [The license: a stab in the dark](https://discuss.elastic.co/t/the-license-a-stab-in-the-dark/69158):

Hi,  
I want to ask whether there is any utility to trigger email before some days of expiration?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![mhgeay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mhgeay/32/21365_2.png) [@mhgeay](https://discuss.elastic.co/u/mhgeay)\
**Post date:** [August 22, 2017, 9:34am UTC](https://discuss.elastic.co/t/x-pack-license-email-triggering/97849/2 "2017-08-22T09:34:13Z")

</div>

Dear Dibyakanta,

You can have details of your current license on your cluster through the API (example result) :

> **GET \_xpack/license**  
> {  
> "license": {  
> "status": "active",  
> "uid": "...",  
> "type": "basic",  
> "issue\_date": "2017-00-00T00:00:00.000Z",  
> "issue\_date\_in\_millis": 140000000000,  
> "expiry\_date": "2018-00-00T23:59:59.999Z",  
> "expiry\_date\_in\_millis": 1500000000,  
> "max\_nodes": 100,  
> "issued\_to": "name (na)",  
> "issuer": "Web Form",  
> "start\_date\_in\_millis": 140000000000  
> }  
> }

Quick solutions :

1. With the X-Pack Alert module (paid subscription) you can create a watch to check the expiration date/timestamp and take action if it's expire in next days.
2. Otherwise you can create a cron script (eg Bash) on your system to check with the API the expiration date.

I don't know if Elastic (the company) send a reminder before the expiration date of each license.

---

<div class="post-metadata">

**Author:** ![Dibyakanta](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@Dibyakanta](https://discuss.elastic.co/u/Dibyakanta)\
**Post date:** [August 22, 2017, 10:05am UTC](https://discuss.elastic.co/t/x-pack-license-email-triggering/97849/3 "2017-08-22T10:05:37Z")

</div>

With the use of Watcher, I am able to send email which will be triggered in a given interval.

Creation of Watcher:-  
PUT /\_xpack/watcher/watch/error\_report  
{  
"trigger" : {  
"schedule": {  
"interval": "1s"  
}  
},  
"actions" : {  
"send\_email" : {  
"email" : {  
"to" : "\ ***_@_**.com",  
"subject" : "Watcher Notification",  
"body" : "Your license will expire soon"  
}  
}  
}  
}

Retrieves the watch:-  
GET /\_xpack/watcher/watch/error\_report.

But, what I want is to trigger a mail automatically as a reminder before the expiration date of a license.

Thank You.

---

<div class="post-metadata">

**Author:** ![mhgeay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mhgeay/32/21365_2.png) [@mhgeay](https://discuss.elastic.co/u/mhgeay)\
**Post date:** [August 22, 2017, 10:19am UTC](https://discuss.elastic.co/t/x-pack-license-email-triggering/97849/4 "2017-08-22T10:19:39Z")

</div>

Ok, you can do it by using **alert conditions** (between your search and action parts) and [compare](https://www.elastic.co/guide/en/x-pack/5.5/condition-compare.html) current date with expiration date.  
Tip : You can use the ctx.execution\_time value as current time to compare dates

btw after read the [manual](https://www.elastic.co/guide/en/x-pack/5.5/license-expiration.html#license-expiration), there are notifications on event :

> "If you’re using X-Pack monitoring and your license will expire within 30 days, a license expiration **warning is displayed** prominently. Warnings are also displayed on startup and written to the Elasticsearch log starting 30 days from the expiration date. "

---

<div class="post-metadata">

**Author:** ![Dibyakanta](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@Dibyakanta](https://discuss.elastic.co/u/Dibyakanta)\
**Post date:** [August 22, 2017, 10:30am UTC](https://discuss.elastic.co/t/x-pack-license-email-triggering/97849/5 "2017-08-22T10:30:33Z")

</div>

Thanks mhgeay. But can you please elaborate me how to use **alert conditions**.

I read the manual. But where will I get those warnings.  
And regarding the logs, as my Xpack is enabled on environment, so I don't have time to see the logs everytime.

Thank you.

---

<div class="post-metadata">

**Author:** ![mhgeay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mhgeay/32/21365_2.png) [@mhgeay](https://discuss.elastic.co/u/mhgeay)\
**Post date:** [August 22, 2017, 11:37am UTC](https://discuss.elastic.co/t/x-pack-license-email-triggering/97849/6 "2017-08-22T11:37:40Z")

</div>

In your posted watch, the trigger (when) is too small, should be daily ; then the input is missing (what search) and to apply action (index, email, API...) on specific conditions, use conditions : when the condition(s) is/are true (= met), action will be applied.  
You should read the [watcher doc](https://www.elastic.co/guide/en/x-pack/5.5/how-watcher-works.html) and [compare](https://www.elastic.co/guide/en/x-pack/5.5/condition-compare.html) conditions doc I linked before. You have good examples on Elastic GitHub [repo](https://github.com/elastic/examples/tree/master/Alerting/Sample%20Watches).

I didn't test my tips/example, so it can be inaccurate.  
instead se of ctx.execution\_time value, try to use a date variable (\<{now+30d}\>) in the condition part :

```
{
  "condition" : {
    "compare" : {
      "ctx.payload.expiry_date" : {
        "lte" : "<{now+30d}>"
      }
  }
}

```

The expiration warning in on Monitoring view as [mentioned](https://discuss.elastic.co/t/the-license-a-stab-in-the-dark/69158/2) by Elastic team in the topic you linked :

> Today, we show this information at the top of the Monitoring Cluster Overview screen, which you can click to see more details, including a link to the subscriptions page above

---

<div class="post-metadata">

**Author:** ![Dibyakanta](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@Dibyakanta](https://discuss.elastic.co/u/Dibyakanta)\
**Post date:** [August 22, 2017, 12:21pm UTC](https://discuss.elastic.co/t/x-pack-license-email-triggering/97849/7 "2017-08-22T12:21:24Z")

</div>

Thanks mhgeay.

I tried with the following code including input and condition.

PUT \_xpack/watcher/watch/x\_pack\_report  
{  
"trigger" : {  
"schedule": {  
"interval": "1d"  
}  
},  
"actions" : {  
"email\_admin" : {  
"email": {  
"to": "recipient.name@xyz.com",  
"subject": "x-pack expiry notification",  
"body":"Your x-pack license will expire in less than 10 days."  
}  
}  
},  
"input" : {  
"http" : {  
"request" : {  
"host" : "localhost",  
"port" : 7200,  
"path" : "\_xpack/license/",  
"auth" : {  
"basic" : {  
"username" : "xyz",  
"password" : "1234"  
}  
}  
}  
}  
},  
"condition" : {  
"compare" :{ "ctx.payload.license.expiry\_date":  
{  
"lte": "\<{now+10d}\>"  
}  
}}  
}

Now I am getting the desired results. The mail is triggered when less than 10 days are remaining for x-pack license expiration date.

Thanks a lot for the help.

---

<div class="post-metadata">

**Author:** ![mhgeay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mhgeay/32/21365_2.png) [@mhgeay](https://discuss.elastic.co/u/mhgeay)\
**Post date:** [August 22, 2017, 12:45pm UTC](https://discuss.elastic.co/t/x-pack-license-email-triggering/97849/8 "2017-08-22T12:45:54Z")

</div>

Hi,

Good news 😉

Tip : you can include variable in your mail, so in your case, the expiration date for example :  
`“body”:“Your x-pack license will expire on {{ctx.payload.license.expiry_date}} (less than 10 days).”`

Bye

---

<div class="post-metadata">

**Author:** ![Dibyakanta](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@Dibyakanta](https://discuss.elastic.co/u/Dibyakanta)\
**Post date:** [August 23, 2017, 4:38am UTC](https://discuss.elastic.co/t/x-pack-license-email-triggering/97849/9 "2017-08-23T04:38:23Z")

</div>

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 20, 2017, 4:38am UTC](https://discuss.elastic.co/t/x-pack-license-email-triggering/97849/10 "2017-09-20T04:38:43Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
