I have tested this out locally and have not been able to reproduce. What 
version of Kapacitor are you using?

I used this TICKscript:

stream
    |from()
        .measurement('test')
    |log()
    |alert()
        .crit(lambda: TRUE)
        .message('{{index .Tags "com.docker.swarm.service.name"}}')
        .log('/tmp/tag.log')

And I wrote a single point: 

test,com.docker.swarm.service.name=jenkins value=1

And got this in the log:

{"id":"test:nil","message":"jenkins","details":"{\u0026#34;Name\u0026#34;:\u0026#34;test\u0026#34;,\u0026#34;TaskName\u0026#34;:\u0026#34;tag\u0026#34;,\u0026#34;Group\u0026#34;:\u0026#34;nil\u0026#34;,\u0026#34;Tags\u0026#34;:{\u0026#34;com.docker.swarm.service.name\u0026#34;:\u0026#34;jenkins\u0026#34;},\u0026#34;ID\u0026#34;:\u0026#34;test:nil\u0026#34;,\u0026#34;Fields\u0026#34;:{\u0026#34;value\u0026#34;:1},\u0026#34;Level\u0026#34;:\u0026#34;CRITICAL\u0026#34;,\u0026#34;Time\u0026#34;:\u0026#34;2017-01-25T17:38:40.004508528Z\u0026#34;,\u0026#34;Message\u0026#34;:\u0026#34;jenkins\u0026#34;}\n","time":"2017-01-25T17:38:40.004508528Z","duration":0,"level":"CRITICAL","data":{"Series":[{"name":"test","tags":{"com.docker.swarm.service.name":"jenkins"},"columns":["time","value"],"values":[["2017-01-25T17:38:40.004508528Z",1]]}],"Messages":null,"Err":null}}

Can you try that simple example and see if that works?
If not please file an issue on github so we can get down to the bottom of 
what is going on. Thanks and sorry for the delayed response.


On Monday, January 16, 2017 at 12:35:35 AM UTC-7, Aditya C.S wrote:
>
> Please require help here. Anyone got any idea?
>
> Regards,
> Aditya C S
>
> On Sat 7 Jan, 2017, 1:41 PM Aditya C.S, <[email protected] <javascript:>> 
> wrote:
>
>> *This is what I get in kapacitor logs*
>>
>> [batch_container_cpu_alert:log3] 2017/01/07 08:06:43 I! 
>>  {"name":"service_cpu_usage","tmax":"2017-01-07T08:05:20Z","group":"
>> com.docker.swarm.service.name=jenkins","tags":{"
>> com.docker.swarm.service.name
>> ":"jenkins"},"points":[{"time":"2017-01-07T08:05:20Z","fields":{"cpu_usage":0.01899111111111111},"tags":{"
>> com.docker.swarm.service.name":"jenkins"}}]}
>>
>> *But in alert log I get null for "com.docker.swarm.service.name 
>> <http://com.docker.swarm.service.name>"*
>>
>> {"id":"service_cpu_usage:com.docker.swarm.service.name=jenkins","message":"INFO:
>>  
>>  has high cpu usage: 
>> 0.048113899999999994","details":"{\u0026#34;Name\u0026#34;:\u0026#34;service_cpu_usage\u0026#34;,\u0026#34;TaskName\u0026#34;:\u0026#34;batch_container_cpu_alert\u0026#34;,\u0026#34;Group\u0026#34;:\u0026#34;
>> com.docker.swarm.service.name
>> =jenkins\u0026#34;,\u0026#34;Tags\u0026#34;:{\u0026#34;
>> com.docker.swarm.service.name
>> \u0026#34;:\u0026#34;jenkins\u0026#34;},\u0026#34;ID\u0026#34;:\u0026#34;service_cpu_usage:
>> com.docker.swarm.service.name=jenkins\u0026#34;,\u0026#34;Fields\u0026#34;:{\u0026#34;cpu_usage\u0026#34;:0.048113899999999994},\u0026#34;Level\u0026#34;:\u0026#34;INFO\u0026#34;,\u0026#34;Time\u0026#34;:\u0026#34;2017-01-01T05:11:00Z\u0026#34;,\u0026#34;Message\u0026#34;:\u0026#34;INFO:
>>  
>> com.docker.swarm.service.name=jenkins: 
>> 0.048113899999999994\u0026#34;}\n","time":"2017-01-01T05:11:00Z","duration":1140000000000,"level":"INFO","data":{"series":[{"name":"service_cpu_usage","tags":{"
>> com.docker.swarm.service.name":"jenkins"},
>>
>> Regards,
>> Aditya C S
>>
>>
>>
>> On Tue, Jan 3, 2017 at 9:44 PM, Ross McDonald <[email protected] 
>> <javascript:>> wrote:
>>
>>> In that case I would recommend adding a `log()` node to your script to 
>>> examine the data before it hits the alert. For example, updating your 
>>> script to look similar to:
>>>
>>>     ...
>>>     |log()
>>>     |alert()
>>>         .message('{{ .Level}}: {{ index .Tags "
>>> com.docker.swarm.service.name" }} has high cpu usage: {{ index .Fields 
>>> "cpu_usage" }}')
>>>     ...
>>>
>>> This will dump all of the data in the stream to the Kapacitor log file. 
>>> Can you provide a few samples from the output when the alert is triggered?
>>>
>>> On Sat, Dec 31, 2016 at 2:11 PM, Aditya C.S <[email protected] 
>>> <javascript:>> wrote:
>>>
>>>> Sorry for the typo.  I have tried {{ index .Tags "
>>>> com.docker.swarm.service.name" }}. 
>>>> It's not working.
>>>>
>>>> Thanks,
>>>> Aditya C S
>>>>
>>>> On Sat 31 Dec, 2016, 11:25 PM Ross McDonald, <[email protected] 
>>>> <javascript:>> wrote:
>>>>
>>>>> Does this not work?
>>>>>
>>>>> {{ index .Tags "com.docker.swarm.service.name" }}
>>>>>
>>>>> There is a space between 'index' and '.Tags'. The brackets need to be 
>>>>> together. And it looks like there is a typo with 'sswarm' (should be 
>>>>> 'swarm').
>>>>>
>>>>> On Fri, Dec 30, 2016 at 11:12 PM, Aditya C.S <[email protected] 
>>>>> <javascript:>> wrote:
>>>>>
>>>>>> How to write custom message with tag value of "
>>>>>> com.docker.swarm.service.name"?. Below is my script. However, tag 
>>>>>> value is displayed as null in the alert. I even tried this way 
>>>>>> ".message('{{ .Level}}: { {index.Tags "[[
>>>>>> com.docker.sswarm.service.name]]" }} has high cpu usage: {{ index 
>>>>>> .Fields "cpu_usage" }}')".
>>>>>>
>>>>>>  batch
>>>>>>     |query('''
>>>>>>          select sum(usage_percent) as cpu_usage from 
>>>>>> "telegraf"."default"."service_cpu_usage" where "
>>>>>> com.docker.swarm.service.name"='jenkins' order by time desc
>>>>>>     ''')
>>>>>>        .period(15m)
>>>>>>        .every(1m)
>>>>>>        .groupBy(time(10s), 'com.docker.swarm.service.name')
>>>>>>
>>>>>>     |alert()
>>>>>>         .message('{{ .Level}}: { {index.Tags "
>>>>>> com.docker.sswarm.service.name" }} has high cpu usage: {{ index 
>>>>>> .Fields "cpu_usage" }}')
>>>>>>         .crit(lambda: "cpu_usage" > 80)
>>>>>>         .log('/opt/kap/container_cpu_alerts.log')
>>>>>>         .exec('/opt/kap/container_cpu_alert.py')
>>>>>>
>>>>>>
>>>>>> Thanks,
>>>>>> Aditya C S
>>>>>>
>>>>>> -- 
>>>>>> Remember to include the version number!
>>>>>> --- 
>>>>>>
>>>>> You received this message because you are subscribed to the Google 
>>>>>> Groups "InfluxData" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it, 
>>>>>> send an email to [email protected] <javascript:>.
>>>>>
>>>>>
>>>>>> To post to this group, send email to [email protected] 
>>>>>> <javascript:>.
>>>>>> Visit this group at https://groups.google.com/group/influxdb.
>>>>>> To view this discussion on the web visit 
>>>>>> https://groups.google.com/d/msgid/influxdb/309d9300-4191-41d7-b727-8ef81ea8da12%40googlegroups.com
>>>>>>  
>>>>>> <https://groups.google.com/d/msgid/influxdb/309d9300-4191-41d7-b727-8ef81ea8da12%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>> .
>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>
>>>>> -- 
>>>>> Remember to include the version number!
>>>>> --- 
>>>>> You received this message because you are subscribed to a topic in the 
>>>>> Google Groups "InfluxData" group.
>>>>> To unsubscribe from this topic, visit 
>>>>> https://groups.google.com/d/topic/influxdb/KEy900H4vtE/unsubscribe.
>>>>> To unsubscribe from this group and all its topics, send an email to 
>>>>> [email protected] <javascript:>.
>>>>> To post to this group, send email to [email protected] 
>>>>> <javascript:>.
>>>>> Visit this group at https://groups.google.com/group/influxdb.
>>>>> To view this discussion on the web visit 
>>>>> https://groups.google.com/d/msgid/influxdb/CAD8sRLBFFX_2ADqdNrotROu-kyFpieiXrqh8v9yi97V0dPk1Vg%40mail.gmail.com
>>>>>  
>>>>> <https://groups.google.com/d/msgid/influxdb/CAD8sRLBFFX_2ADqdNrotROu-kyFpieiXrqh8v9yi97V0dPk1Vg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>> -- 
>>>> Remember to include the version number!
>>>> --- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "InfluxData" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to [email protected] <javascript:>.
>>>> To post to this group, send email to [email protected] 
>>>> <javascript:>.
>>>> Visit this group at https://groups.google.com/group/influxdb.
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/influxdb/CAFEGz4maC9HDMYwnO0m2LN2KQKRNO98ZJfFfHnwt-sSW5VgRkg%40mail.gmail.com
>>>>  
>>>> <https://groups.google.com/d/msgid/influxdb/CAFEGz4maC9HDMYwnO0m2LN2KQKRNO98ZJfFfHnwt-sSW5VgRkg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>> -- 
>>> Remember to include the version number!
>>> --- 
>>> You received this message because you are subscribed to a topic in the 
>>> Google Groups "InfluxData" group.
>>> To unsubscribe from this topic, visit 
>>> https://groups.google.com/d/topic/influxdb/KEy900H4vtE/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to 
>>> [email protected] <javascript:>.
>>> To post to this group, send email to [email protected] 
>>> <javascript:>.
>>> Visit this group at https://groups.google.com/group/influxdb.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/influxdb/CAD8sRLDBF8A-a%3Dhjf9eSfp2es4EYA2E%2B1uEujGsQrnSAyoA6Fw%40mail.gmail.com
>>>  
>>> <https://groups.google.com/d/msgid/influxdb/CAD8sRLDBF8A-a%3Dhjf9eSfp2es4EYA2E%2B1uEujGsQrnSAyoA6Fw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>

-- 
Remember to include the version number!
--- 
You received this message because you are subscribed to the Google Groups 
"InfluxData" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/influxdb.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/influxdb/6fce6b4a-fcba-4755-930f-42749c564fc5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to