{"action":"closed","issue":{"url":"https://api.github.com/repos/influxdata/kapacitor/issues/1227","repository_url":"https://api.github.com/repos/influxdata/kapacitor","labels_url":"https://api.github.com/repos/influxdata/kapacitor/issues/1227/labels{/name}","comments_url":"https://api.github.com/repos/influxdata/kapacitor/issues/1227/comments","events_url":"https://api.github.com/repos/influxdata/kapacitor/issues/1227/events","html_url":"https://github.com/influxdata/kapacitor/issues/1227","id":210374726,"number":1227,"title":"kapacitor template : pass function name as variable.","user":{"login":"chetu","id":395601,"avatar_url":"https://avatars.githubusercontent.com/u/395601?v=3","gravatar_id":"","url":"https://api.github.com/users/chetu","html_url":"https://github.com/chetu","followers_url":"https://api.github.com/users/chetu/followers","following_url":"https://api.github.com/users/chetu/following{/other_user}","gists_url":"https://api.github.com/users/chetu/gists{/gist_id}","starred_url":"https://api.github.com/users/chetu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chetu/subscriptions","organizations_url":"https://api.github.com/users/chetu/orgs","repos_url":"https://api.github.com/users/chetu/repos","events_url":"https://api.github.com/users/chetu/events{/privacy}","received_events_url":"https://api.github.com/users/chetu/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-02-27T02:46:04Z","updated_at":"2017-02-28T02:58:11Z","closed_at":"2017-02-28T02:58:11Z","body":"We trying to use single tick to define various tasks.\r\n\r\nin order to use same template for all tasks need to pass different functions.\r\n\r\nwill it be possible.\r\n\r\nmy tick script is \r\n\r\n```\r\n// Which measurement to consume\r\nvar measurement string\r\n// Optional where filter\r\nvar where_filter = lambda: TRUE\r\n// Optional list of group by dimensions\r\nvar groups = [*]\r\n// Which field to process\r\nvar field string\r\n// Warning criteria \r\nvar warn = lambda: FALSE\r\n// Critical criteria\r\nvar crit = lambda: FALSE\r\n// How much data to window\r\nvar period = 5m\r\n// How many times to check in window\r\nvar every = 1m\r\n// The topic name to subscribe\r\nvar topic_name  string\r\n// The function name to pass\r\n**function_name string**\r\n// The email message boby details\r\nvar details = TASKS' DETAILS'\r\n\r\nstream\r\n    |from()\r\n        .measurement(measurement)\r\n        .where(where_filter)\r\n        .groupBy('host')\r\n    |window()\r\n        .period(period)\r\n        .every(every)\r\n    |**function_name**(field)\r\n        .as(field)\r\n    |alert()\r\n         //.warn(warn)\r\n         .crit(crit)\r\n         .stateChangesOnly(5m)\r\n         .message('{{ if eq .Level \"OK\" }} | RECOVERY | {{ else }} | {{ .Level }} | {{ end }} ' + measurement + '.' + field + ' | {{ index .Tags \"host\" }} |')\r\n         .details(details)\r\n         .topic(topic_name)\r\n```\r\n\r\n**JSON var** \r\n\r\n```json\r\n{\r\n    \"measurement\": {\"type\" : \"string\", \"value\" : \"mem\" },\r\n    \"groups\": {\"type\": \"list\", \"value\": [{\"type\":\"string\", \"value\":\"host\"}]},\r\n    \"field\": {\"type\" : \"string\", \"value\" : \"used_percent\" },\r\n    \"**function_name**\": {\"type\" : \"string\", \"value\" : \"last\" },\r\n    \"warn\": {\"type\" : \"lambda\", \"value\" : \"\\\"used_percent\\\" > 80\" },\r\n    \"crit\": {\"type\" : \"lambda\", \"value\" : \"\\\"used_percent\\\" >= 99\" },\r\n    \"topic_name\": { \"type\" : \"string\", \"value\" : \"prod\"},\r\n    \"period\": {\"type\" : \"duration\", \"value\" : \"5m\" },\r\n    \"every\": {\"type\" : \"duration\", \"value\" : \"1m\" }\r\n}\r\n```\r\n\r\n```\r\nkapacitor define-template test -tick /etc/kapacitor/templates/test.tick -type stream\r\nkapacitor define test -template test -vars /etc/kapacitor/tasks/test.json -dbrp prod.1y\r\nkapacitor enable test\r\n```\r\n\r\n**ERROR**\r\n\r\n```\r\n_root@kapacitor-influx:/# kapacitor define-template test -tick /etc/kapacitor/templates/test.tick -type stream\r\ninvalid TICKscript: line 54 char 6: no method or property \"function_name\" on *pipeline.WindowNode\r\nroot@kapacitor-influx:/# kapacitor define test -template test -vars /etc/kapacitor/tasks/test.json -dbrp prod.1y\r\nunknown template test: err: no template exists_\r\n```"}}
{"actor":{"display_login":"chetu"}}