X-pack license email triggering


(Dibyakanta Sahoo) #1

Continuing the discussion from The license: a stab in the dark:

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

Thanks in advance.


(MH) #2

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.


(Dibyakanta Sahoo) #3

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.


(MH) #4

Ok, you can do it by using alert conditions (between your search and action parts) and compare 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, 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. "


(Dibyakanta Sahoo) #5

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.


(MH) #6

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 and compare conditions doc I linked before. You have good examples on Elastic GitHub repo.

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 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


(Dibyakanta Sahoo) #7

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.


(MH) #8

Hi,

Good news :wink:

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


(Dibyakanta Sahoo) #9

Thanks a lot.


(system) #10

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