# Rocket.Chat notification help

**URL:** <https://community.icinga.com/t/rocket-chat-notification-help/10243>\
**Category:** Visualization, Metrics & Reporting\
**Tags:** notifications, api, director, icinga2\
**Created:** [July 25, 2022, 3:33pm UTC](https://community.icinga.com/t/rocket-chat-notification-help/10243 "2022-07-25T15:33:41Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![329854343](https://community.icinga.com/letter_avatar_proxy/v4/letter/3/7993a0/32.png) [@329854343](https://community.icinga.com/u/329854343)\
**Post date:** [July 25, 2022, 3:33pm UTC](https://community.icinga.com/t/rocket-chat-notification-help/10243/1 "2022-07-25T15:33:41Z")

</div>

Hello again,

I want to send info notification to a rocket.chat channel.

I’ve followed the official [guide](https://icinga.com/blog/2021/11/24/icinga-2-rocket-chat-notifications-the-complete-guide/), but I don’t get it to work.  
I use the icinga2 Director module to create the commands, one thing is diffrent in my configuration - I don’t know how to create the `env = { ...` variable as seen in [github](https://github.com/Al2Klimov/notify_rocketchat/blob/master/icinga2/command.conf).

My command configuration:

## zones.d/director-global/commands.conf

```auto
zones.d/director-global/commands.conf
object NotificationCommand "rocketchat" {
    import "plugin-notification-command"
    command = ["/etc/icinga2/scripts/notify_rocketchat"]
    arguments += {
        "-host.action_url" = "$rocketchat_host_action_url$"
        "-host.display_name" = "$host.display_name$"
        "-host.name" = "$host.name$"
        "-host.output" = "$host.output$"
        "-host.state" = "$host.state$"
        "-icinga.timet" = "$icinga.timet$"
        "-service.action_url" = "$rocketchat_service_action_url$"
        "-service.display_name" = "$service.display_name$"
        "-service.name" = "$service.name$"
        "-service.output" = "$service.output$"
        "-service.state" = "$service.state$"
    }
    vars.rocketchat_host_action_url = "$host.action_url$"
    vars.rocketchat_service_action_url = "$service.action_url$"
}

```

My notification template looks like this:

## zones.d/s060w44/notification\_templates.conf

```auto
template Notification "rocketchat-notifiy-template" {
    command = "rocketchat"
    states = [Critical, OK]
    types = [Acknowledgement, Problem, Recovery]
    users = ["rocket.chat"]
}

```

.. and both notification commands look like this:

## zones.d/s060w44/notification\_apply.conf

```auto
apply Notification "host rocketchat" to Host {
    import "rocketchat-notifiy-template"

    assign where match("*", host.name)
    states = [Down, Up]
    types = [Acknowledgement, Custom, Problem, Recovery]
    users = ["rocket.chat"]
    vars.rocketchat_host_action_url = "https://URL/hooks/6xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    vars.rocketchat_service_action_url = "https://URL/hooks/6xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}

```

## zones.d/s060w44/notification\_apply.conf

```auto
zones.d/s060w44/notification_apply.conf
apply Notification "service rocketchat" to Service {
    import "rocketchat-notifiy-template"

    assign where match("*", host.name)
    states = [Critical, OK]
    types = [Acknowledgement, Problem, Recovery]
    users = ["rocket.chat"]
    vars.rocketchat_host_action_url = "https://URL/hooks/6xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    vars.rocketchat_service_action_url = "https://URL/hooks/6xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

```

}

Thanks for any help!

---

<div class="post-metadata">

**Author:** ![moreamazingnick](https://community.icinga.com/user_avatar/community.icinga.com/moreamazingnick/32/7725_2.png) [@moreamazingnick](https://community.icinga.com/u/moreamazingnick)\
**Post date:** [July 26, 2022, 6:28am UTC](https://community.icinga.com/t/rocket-chat-notification-help/10243/2 "2022-07-26T06:28:03Z")

</div>

change the command in commands.conf to:  
`/usr/bin/env ROCKETCHAT_WEBHOOK_URL="https://test/hook" /etc/icinga2/scripts/notify_rocketchat`

I tested it out with:  
`/usr/bin/env ROCKETCHAT_WEBHOOK_URL="https://test/hook" printenv`

---

<div class="post-metadata">

**Author:** ![329854343](https://community.icinga.com/letter_avatar_proxy/v4/letter/3/7993a0/32.png) [@329854343](https://community.icinga.com/u/329854343)\
**Post date:** [July 26, 2022, 9:19am UTC](https://community.icinga.com/t/rocket-chat-notification-help/10243/3 "2022-07-26T09:19:50Z")

</div>

Hello, how/where do I do this in icinga2 director?

 ![image](https://community.icinga.com/uploads/default/original/2X/7/7f546cde509d81fb66fe0d8473ef5f7379ff30da.png)

 ![image](https://community.icinga.com/uploads/default/original/2X/e/ec2defb2c3964d7c4e503364b9e76869064b37cb.png)

 ![image](https://community.icinga.com/uploads/default/original/2X/3/32b242f44d758bae4fcc69ef89b5ad1d81fdd4fc.png)

Thanks

---

<div class="post-metadata">

**Author:** ![moreamazingnick](https://community.icinga.com/user_avatar/community.icinga.com/moreamazingnick/32/7725_2.png) [@moreamazingnick](https://community.icinga.com/u/moreamazingnick)\
**Post date:** [July 26, 2022, 9:22am UTC](https://community.icinga.com/t/rocket-chat-notification-help/10243/4 "2022-07-26T09:22:38Z")

</div>

first picture:

replace

`/etc/icinga2/scripts/notify_rocketchat`

with:

`/usr/bin/env ROCKETCHAT_WEBHOOK_URL="https://test/hook" /etc/icinga2/scripts/notify_rocketchat`

---

<div class="post-metadata">

**Author:** ![329854343](https://community.icinga.com/letter_avatar_proxy/v4/letter/3/7993a0/32.png) [@329854343](https://community.icinga.com/u/329854343)\
**Post date:** [July 26, 2022, 9:47am UTC](https://community.icinga.com/t/rocket-chat-notification-help/10243/5 "2022-07-26T09:47:00Z")

</div>

Hello, I’ve past the string (/usr/bin/env ROCKETCHAT\_WEBHOOK\_URL=“[https://url](https://url)” /etc/icinga2/scripts/notify\_rocketchat) in the command field.

```auto
zones.d/director-global/commands.conf
object NotificationCommand "rocketchat" {
    import "plugin-notification-command"
    command = [
        "/usr/bin/env",
        "ROCKETCHAT_WEBHOOK_URL=\"https://url\"",
        "/etc/icinga2/scripts/notify_rocketchat"
    ]
    arguments += {
        "-host.action_url" = "$rocketchat_host_action_url$"
        "-host.display_name" = "$host.display_name$"
        "-host.name" = "$host.name$"
        "-host.output" = "$host.output$"
        "-host.state" = "$host.state$"
        "-icinga.timet" = "$icinga.timet$"
        "-service.action_url" = "$rocketchat_service_action_url$"
        "-service.display_name" = "$service.display_name$"
        "-service.name" = "$service.name$"
        "-service.output" = "$service.output$"
        "-service.state" = "$service.state$"
    }
    vars.rocketchat_host_action_url = "$host.action_url$"
    vars.rocketchat_service_action_url = "$service.action_url$"
}

```

I don’t think the director acknowledge that `/usr/bin/env ROCKETCHAT_WEBHOOK_URL=` is 1 command because it sets a comma. Or did I do something wrong?

Thanks

---

<div class="post-metadata">

**Author:** ![moreamazingnick](https://community.icinga.com/user_avatar/community.icinga.com/moreamazingnick/32/7725_2.png) [@moreamazingnick](https://community.icinga.com/u/moreamazingnick)\
**Post date:** [July 26, 2022, 9:49am UTC](https://community.icinga.com/t/rocket-chat-notification-help/10243/6 "2022-07-26T09:49:59Z")

</div>

looks fine to me,

my test command renderd to

```auto
object CheckCommand "envtest" {
    import "plugin-check-command"
    command = [
        "/usr/bin/env",
        "ROCKETCHAT_WEBHOOK_URL=\"https://test/hook\"",
        "printenv"
    ]
}

```

and produced the following output:

```auto
PIDFILE=/run/icinga2/icinga2.pid
PWD=/
LANG=en_US.UTF-8
INVOCATION_ID=148ff0e1959d42f281ddf932ead25000
SHLVL=0
ICINGA2_ERROR_LOG=/var/log/icinga2/error.log
JOURNAL_STREAM=9:34313
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
LC_NUMERIC=C
ROCKETCHAT_WEBHOOK_URL="https://test/hook"

```

---

<div class="post-metadata">

**Author:** ![329854343](https://community.icinga.com/letter_avatar_proxy/v4/letter/3/7993a0/32.png) [@329854343](https://community.icinga.com/u/329854343)\
**Post date:** [July 26, 2022, 10:10am UTC](https://community.icinga.com/t/rocket-chat-notification-help/10243/7 "2022-07-26T10:10:39Z")

</div>

Okay, right now I get no messages, how can I test run it like you did?

---

<div class="post-metadata">

**Author:** ![moreamazingnick](https://community.icinga.com/user_avatar/community.icinga.com/moreamazingnick/32/7725_2.png) [@moreamazingnick](https://community.icinga.com/u/moreamazingnick)\
**Post date:** [July 26, 2022, 1:16pm UTC](https://community.icinga.com/t/rocket-chat-notification-help/10243/8 "2022-07-26T13:16:46Z")

</div>

try to run the go command manually (from shell) first, so we can exclude any configuration issues on the rocketchat side

---

<div class="post-metadata">

**Author:** ![329854343](https://community.icinga.com/letter_avatar_proxy/v4/letter/3/7993a0/32.png) [@329854343](https://community.icinga.com/u/329854343)\
**Post date:** [July 26, 2022, 1:38pm UTC](https://community.icinga.com/t/rocket-chat-notification-help/10243/9 "2022-07-26T13:38:42Z")

</div>

Did you mean this?

```auto
root@Server:/etc/icinga2/scripts# /etc/icinga2/scripts/notify_rocketchat
$ROCKETCHAT_WEBHOOK_URL missing
root@Server:/etc/icinga2/scripts#

```

---

<div class="post-metadata">

**Author:** ![moreamazingnick](https://community.icinga.com/user_avatar/community.icinga.com/moreamazingnick/32/7725_2.png) [@moreamazingnick](https://community.icinga.com/u/moreamazingnick)\
**Post date:** [July 27, 2022, 6:47am UTC](https://community.icinga.com/t/rocket-chat-notification-help/10243/10 "2022-07-27T06:47:49Z")

</div>

yes but your command is incomplete:

1. read the documentation on notify\_rocketchat
2. set the environmentvar of the url via export
3. prepare the shell command
4. run it and see if that works and connects to your rocketchat instance

---

<div class="post-metadata">

**Author:** ![329854343](https://community.icinga.com/letter_avatar_proxy/v4/letter/3/7993a0/32.png) [@329854343](https://community.icinga.com/u/329854343)\
**Post date:** [July 27, 2022, 10:03am UTC](https://community.icinga.com/t/rocket-chat-notification-help/10243/11 "2022-07-27T10:03:35Z")

</div>

Hello, I think I do someting wrong with setting a variable as shown in the documentation.

```auto
root@s060w44:~# /etc/icinga2/scripts/notify_rocketchat env={"ROCKETCHAT_WEBHOOK_URL" = "https://URL"}
$ROCKETCHAT_WEBHOOK_URL missing
root@s060w44:~# /etc/icinga2/scripts/notify_rocketchat vars.rocketchat_webhook_url="https://URL"
$ROCKETCHAT_WEBHOOK_URL missing
root@s060w44:~#

```

But I can run a curl command to the rocket.chat webhook, so connection should not be a problem.

---

<div class="post-metadata">

**Author:** ![moreamazingnick](https://community.icinga.com/user_avatar/community.icinga.com/moreamazingnick/32/7725_2.png) [@moreamazingnick](https://community.icinga.com/u/moreamazingnick)\
**Post date:** [July 27, 2022, 10:26am UTC](https://community.icinga.com/t/rocket-chat-notification-help/10243/12 "2022-07-27T10:26:01Z")

</div>

> [@329854343](#):
>
> `env`

please look up who to set an environment variable in bash.

ROCKETCHAT\_WEBHOOK\_URL is an environment variable

[https://www.google.com/search?q=set+environment+var+in+bash&oq=set+environment+var+in+bash](https://www.google.com/search?q=set+environment+var+in+bash&oq=set+environment+var+in+bash)

---

<div class="post-metadata">

**Author:** ![329854343](https://community.icinga.com/letter_avatar_proxy/v4/letter/3/7993a0/32.png) [@329854343](https://community.icinga.com/u/329854343)\
**Post date:** [July 27, 2022, 12:25pm UTC](https://community.icinga.com/t/rocket-chat-notification-help/10243/13 "2022-07-27T12:25:58Z")

</div>

Hello, communication works:

```auto
/etc/icinga2/scripts/notify_rocketchat -host.name hostname -host.state down -host.name hostname -service.name ping -service.state up

```

Result:  
 ![image](https://community.icinga.com/uploads/default/original/2X/5/553853369d8429d2384f08e24d57e044fa938c25.png)

---

<div class="post-metadata">

**Author:** ![moreamazingnick](https://community.icinga.com/user_avatar/community.icinga.com/moreamazingnick/32/7725_2.png) [@moreamazingnick](https://community.icinga.com/u/moreamazingnick)\
**Post date:** [July 27, 2022, 12:38pm UTC](https://community.icinga.com/t/rocket-chat-notification-help/10243/14 "2022-07-27T12:38:40Z")

</div>

well thats great,  
please try if that works and replace the webhook url:

```auto
/usr/bin/env ROCKETCHAT_WEBHOOK_URL="https://test/hook" /etc/icinga2/scripts/notify_rocketchat -host.name hostname -host.state down -host.name hostname -service.name ping -service.state up

```

---

<div class="post-metadata">

**Author:** ![329854343](https://community.icinga.com/letter_avatar_proxy/v4/letter/3/7993a0/32.png) [@329854343](https://community.icinga.com/u/329854343)\
**Post date:** [July 27, 2022, 1:02pm UTC](https://community.icinga.com/t/rocket-chat-notification-help/10243/15 "2022-07-27T13:02:29Z")

</div>

Yes, this works aswell!

---

<div class="post-metadata">

**Author:** ![moreamazingnick](https://community.icinga.com/user_avatar/community.icinga.com/moreamazingnick/32/7725_2.png) [@moreamazingnick](https://community.icinga.com/u/moreamazingnick)\
**Post date:** [July 27, 2022, 1:06pm UTC](https://community.icinga.com/t/rocket-chat-notification-help/10243/16 "2022-07-27T13:06:14Z")

</div>

if you look up a service or a host in icingaweb, what do you see under the section Notifications?

---

<div class="post-metadata">

**Author:** ![329854343](https://community.icinga.com/letter_avatar_proxy/v4/letter/3/7993a0/32.png) [@329854343](https://community.icinga.com/u/329854343)\
**Post date:** [July 27, 2022, 1:10pm UTC](https://community.icinga.com/t/rocket-chat-notification-help/10243/17 "2022-07-27T13:10:58Z")

</div>

![image](https://community.icinga.com/uploads/default/original/2X/a/a78ff5ac07c849c59606cf484a1e7e68cc5063bd.png)

---

<div class="post-metadata">

**Author:** ![moreamazingnick](https://community.icinga.com/user_avatar/community.icinga.com/moreamazingnick/32/7725_2.png) [@moreamazingnick](https://community.icinga.com/u/moreamazingnick)\
**Post date:** [July 27, 2022, 1:18pm UTC](https://community.icinga.com/t/rocket-chat-notification-help/10243/18 "2022-07-27T13:18:01Z")

</div>

looks great so the service sends notifications

look into the icigna2.log and search for notification

---

<div class="post-metadata">

**Author:** ![329854343](https://community.icinga.com/letter_avatar_proxy/v4/letter/3/7993a0/32.png) [@329854343](https://community.icinga.com/u/329854343)\
**Post date:** [July 28, 2022, 11:20am UTC](https://community.icinga.com/t/rocket-chat-notification-help/10243/19 "2022-07-28T11:20:37Z")

</div>

Hello, this is the output.

```auto
[2022-07-28 10:59:37 +0000] debug/HttpUtility: Request body: '{"author":"Username","comment":"test","force":false,"host":"test"}'
....
[2022-07-28 10:59:37 +0000] information/Notification: Completed sending 'Custom' notification 'test!host rocketchat' for checkable 'test' and user 'rocket.chat' using command 'rocketchat_alt'.
[2022-07-28 10:59:37 +0000] notice/Process: PID 1242560 ('/usr/bin/env' 'ROCKETCHAT_WEBHOOK_URL="https://URL/hooks/"' '/etc/icinga2/scripts/notify_rocketchat' '-host.action_url' 'https://URL/hooks/' '-host.display_name' 'test' '-host.name' 'test' '-host.output' 'PING CRITICAL - Packet loss = 100%' '-host.state' 'DOWN' '-icinga.timet' '1659005977' '-service.action_url' 'https://URL/hooks/') terminated with exit code 2
[2022-07-28 10:59:37 +0000] warning/PluginNotificationTask: Notification command for object 'test' (PID: 1242560, arguments: '/usr/bin/env' 'ROCKETCHAT_WEBHOOK_URL="https://URL/hooks/"' '/etc/icinga2/scripts/notify_rocketchat' '-host.action_url' 'https://URL/hooks/' '-host.display_name' 'test' '-host.name' 'test' '-host.output' 'PING CRITICAL - Packet loss = 100%' '-host.state' 'DOWN' '-icinga.timet' '1659005977' '-service.action_url' 'https://URL/hooks/') terminated with exit code 2, output: -service.* is given, missing some of: -host.name, -service.name, -service.state

```

---

<div class="post-metadata">

**Author:** ![moreamazingnick](https://community.icinga.com/user_avatar/community.icinga.com/moreamazingnick/32/7725_2.png) [@moreamazingnick](https://community.icinga.com/u/moreamazingnick)\
**Post date:** [July 28, 2022, 11:40am UTC](https://community.icinga.com/t/rocket-chat-notification-help/10243/20 "2022-07-28T11:40:42Z")

</div>

your host notification is not working because the service action url is set

remove from `Notification "host rocketchat" to Host`

```auto
vars.rocketchat_service_action_url = "https://URL/hooks/6xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

```

[Next page](https://community.icinga.com/t/rocket-chat-notification-help/10243.md?page=2)
