# Env variables are being taken in count?

**URL:** <https://community.icinga.com/t/env-variables-are-being-taken-in-count/11063>\
**Category:** Icinga 2\
**Created:** [November 22, 2022, 5:45am UTC](https://community.icinga.com/t/env-variables-are-being-taken-in-count/11063 "2022-11-22T05:45:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![WEBudoGT](https://community.icinga.com/letter_avatar_proxy/v4/letter/w/65b543/32.png) [@WEBudoGT](https://community.icinga.com/u/WEBudoGT)\
**Post date:** [November 22, 2022, 5:45am UTC](https://community.icinga.com/t/env-variables-are-being-taken-in-count/11063/1 "2022-11-22T05:45:03Z")

</div>

I’m trying to use a telegram notification script I found here ([GitHub - TeraIT-at/icinga-telegram-bot: Telegram Bot for Icinga2](https://github.com/TeraIT-at/icinga-telegram-bot))  
For the notification definition it uses env variables and it’s defined as follows:

```auto
object NotificationCommand "telegram-host-notification" {
  import "plugin-notification-command"

  command = [SysconfDir + "/icinga2/scripts/telegram-host-notification.sh"]

  env = {
    NOTIFICATIONTYPE = "$notification.type$"
    HOSTNAME = "$host.name$"
    HOSTALIAS = "$host.display_name$"
    HOSTADDRESS = "$address$"
    HOSTSTATE = "$host.state$"
    LONGDATETIME = "$icinga.long_date_time$"
    HOSTOUTPUT = "$host.output$"
    NOTIFICATIONAUTHORNAME = "$notification.author$"
    NOTIFICATIONCOMMENT = "$notification.comment$"
    HOSTDISPLAYNAME = "$host.display_name$"
    TELEGRAM_BOT_TOKEN = "here_i_put_my_token"
    TELEGRAM_CHAT_ID = "$user.vars.telegram_chat_id$"

    // optional
    ICINGAWEB2_URL = "https://myicingaurl/icingaweb2"
  }
}

```

When icinga calls the script it does nothing (and I don’t know how to debug). But I’m guessing it’s because the env variables are not being set, because when on director I open the definition it’s just like this:

```auto
object NotificationCommand "telegram-host-notification" {
    import "plugin-notification-command"
    command = ["/etc/icinga2/scripts/telegram-host-notification.sh"]
    timeout = 1m
}

```

How do I enable icinga to use env variables? How to test if those are being set?

Thanks in advance

- Version used (`icinga2 --version`)  
version: r2.13.6-1

- Operating System and version  
Platform: Debian GNU/Linux  
Platform version: 11 (bullseye)  
Kernel: Linux  
Kernel version: 5.10.0-19-amd64  
Architecture: x86\_64

- Enabled features (`icinga2 feature list`)  
Disabled features: command compatlog debuglog elasticsearch gelf graphite influxdb influxdb2 livestatus opentsdb perfdata statusdata syslog  
Enabled features: api checker icingadb mainlog notification

---

<div class="post-metadata">

**Author:** ![rivad](https://community.icinga.com/user_avatar/community.icinga.com/rivad/32/5852_2.png) [@rivad](https://community.icinga.com/u/rivad)\
**Post date:** [November 22, 2022, 9:04am UTC](https://community.icinga.com/t/env-variables-are-being-taken-in-count/11063/2 "2022-11-22T09:04:04Z")

</div>

Do you want to manage this in the classical DSL or in the Director?  
What is the active configuration? You can check with: `$ icinga2 object list`

---

<div class="post-metadata">

**Author:** ![WEBudoGT](https://community.icinga.com/letter_avatar_proxy/v4/letter/w/65b543/32.png) [@WEBudoGT](https://community.icinga.com/u/WEBudoGT)\
**Post date:** [November 22, 2022, 5:21pm UTC](https://community.icinga.com/t/env-variables-are-being-taken-in-count/11063/3 "2022-11-22T17:21:12Z")

</div>

Hello Dominik

Want to use Director (I’m so new to icinga that I guess DSL would just complicate things for me).  
Thanks for the `$ icinga2 object list` command.  
When running it, the check-command does contain the env variables:

```auto
Object 'telegram-service-notification' of type 'NotificationCommand':
  % declared in '/etc/icinga2/conf.d/telegram_commands.conf', lines 26:1-26:58
  * __name = "telegram-service-notification"
  * arguments = null
  * command = ["/etc/icinga2/scripts/telegram-service-notification.sh"]
    % = modified in '/etc/icinga2/conf.d/telegram_commands.conf', lines 29:3-29:80
  * env
    % = modified in '/etc/icinga2/conf.d/telegram_commands.conf', lines 31:3-49:3
    * HOSTADDRESS = "$address$"
    * HOSTALIAS = "$host.display_name$"
    * HOSTDISPLAYNAME = "$host.display_name$"
    * HOSTNAME = "$host.name$"
    * ICINGAWEB2_URL = "https://myicingadomain.tld/icingaweb2"
    * LONGDATETIME = "$icinga.long_date_time$"
    * NOTIFICATIONAUTHORNAME = "$notification.author$"
    * NOTIFICATIONCOMMENT = "$notification.comment$"
    * NOTIFICATIONTYPE = "$notification.type$"
    * SERVICEDESC = "$service.name$"
    * SERVICEDISPLAYNAME = "$service.display_name$"
    * SERVICEOUTPUT = "$service.output$"
    * SERVICESTATE = "$service.state$"
    * TELEGRAM_BOT_TOKEN = "token_goes_here"
    * TELEGRAM_CHAT_ID = "$user.vars.telegram_chat_id$"
  * execute
    % = modified in 'methods-itl.conf', lines 23:3-23:30
    % = modified in 'methods-itl.conf', lines 23:3-23:30
    * arguments = ["notification", "user", "cr", "itype", "author", "comment", "resolvedMacros", "useResolvedMacros"]
    * deprecated = false
    * name = "Internal#PluginNotification"
    * side_effect_free = false
    * type = "Function"
  * name = "telegram-service-notification"
  * package = "_etc"
  * source_location
    * first_column = 1
    * first_line = 26
    * last_column = 58
    * last_line = 26
    * path = "/etc/icinga2/conf.d/telegram_commands.conf"
  * templates = ["telegram-service-notification", "plugin-notification-command", "plugin-notification-command"]
    % = modified in '/etc/icinga2/conf.d/telegram_commands.conf', lines 26:1-26:58
    % = modified in 'methods-itl.conf', lines 22:2-22:122
    % = modified in 'methods-itl.conf', lines 22:2-22:122
  * timeout = 60
  * type = "NotificationCommand"
  * vars = null
  * zone = ""

```

Is there a way I can debug what happens when Icinga runs the .sh script?

---

<div class="post-metadata">

**Author:** ![rivad](https://community.icinga.com/user_avatar/community.icinga.com/rivad/32/5852_2.png) [@rivad](https://community.icinga.com/u/rivad)\
**Post date:** [November 22, 2022, 5:48pm UTC](https://community.icinga.com/t/env-variables-are-being-taken-in-count/11063/4 "2022-11-22T17:48:40Z")

</div>

Sure, have a look at [Troubleshooting - Icinga 2](https://icinga.com/docs/icinga-2/latest/doc/15-troubleshooting/#notifications-troubleshooting) - be careful to restart icinga every time you enable and disable debug log or it will not work also don’t forget to disable it or your disk can fill up quickly!  
Maybe temporarily replace telegram-service-notification.sh with:

```auto
/bin/bash
touch /tmp/debug_notification.log # create log
chmod 600 /tmp/debug_notification.log # secure it
env > /tmp/debug_notification.log # get the env vars
echo $@ >> /temp/debug_notification.log # get all attributes

```

to dump all information that was given to it.

---

<div class="post-metadata">

**Author:** ![WEBudoGT](https://community.icinga.com/letter_avatar_proxy/v4/letter/w/65b543/32.png) [@WEBudoGT](https://community.icinga.com/u/WEBudoGT)\
**Post date:** [November 23, 2022, 6:10pm UTC](https://community.icinga.com/t/env-variables-are-being-taken-in-count/11063/5 "2022-11-23T18:10:49Z")

</div>

Thanks Dominik!

Got it working after some debugging 🙂

---

<div class="post-metadata">

**Author:** ![theFeu](https://community.icinga.com/user_avatar/community.icinga.com/thefeu/32/7277_2.png) [@theFeu](https://community.icinga.com/u/theFeu)\
**Post date:** [November 28, 2022, 11:42am UTC](https://community.icinga.com/t/env-variables-are-being-taken-in-count/11063/6 "2022-11-28T11:42:24Z")

</div>

If your topic is resolved, please also make sure to mark the response that helped you solve it as the “solution” by clicking the three dots on that message. 🙂

If the solution can’t be found in a single answer, it would be super helpful, if you could write a summary of what helped and marked this as the solution. This way users with a similar problem can solve their issues a lot easier. Thank you!
