Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContactPoints: incorrect substitution of enviroment values in yaml config #69950

Open
casnerano opened this issue Jun 12, 2023 · 6 comments · May be fixed by grafana/alerting#198
Open

ContactPoints: incorrect substitution of enviroment values in yaml config #69950

casnerano opened this issue Jun 12, 2023 · 6 comments · May be fixed by grafana/alerting#198

Comments

@casnerano
Copy link

casnerano commented Jun 12, 2023

What went wrong?

What happened:

In configuration file etc/grafana/provisioning/alerting/default.yml

the Point of Contact for the telegram is declared, the ChatId value is taken from the environment variables.

contactPoints:
   - orgId: 1

     name: Telegram
     receivers:
       - uid: telegram_notifier
         type: telegram
         settings:
           bottoken: $TELEGRAM_TOKEN
           chatid: $TELEGRAM_CHAT_ID

env variable value
TELEGRAM_CHAT_ID="-808008888"

When starting grafana, an error pops up:
Error: ✗ failure to map file default.yml: failure parsing contact points: Telegram: failed to validate receiver of type "telegram": failed to unmarshal settings: json: cannot unmarshal number into Go struct field Config.chatid of type string

The problem is not solved, even if you wrap the value in quotes:
chatid: "$TELEGRAM_CHAT_ID"

The problem was solved temporarily through a crutch:
env variable value TELEGRAM_CHAT_ID="808008888"
in config:

chatid: |-
   -
   $TELEGRAM_CHAT_ID

The problem is that when substituting a value from an environment variable, it is interpreted as a negative number, and not as a string, which the structure expects.

How do we reproduce it?

In configuration file etc/grafana/provisioning/alerting/default.yml

contactPoints:
   - orgId: 1

     name: Telegram
     receivers:
       - uid: telegram_notifier
         type: telegram
         settings:
           bottoken: $TELEGRAM_TOKEN
           chatid: $TELEGRAM_CHAT_ID

where $TELEGRAM_CHAT_ID is number.

What Grafana version are you using?

v9.5.2

Optional Questions:

Is the bug inside a Dashboard Panel?

Copy the panel's "get-help" data here

Grafana Platform?

Docker

User's OS?

No response

User's Browser?

No response

Is this a Regression?

None

Are Datasources involved?

No response

Anything else to add?

No response

@casnerano casnerano changed the title Product-Area-Here: short description of bug here ContactPoints: incorrect substitution of enviroment values in yaml config Jun 13, 2023
@zuchka zuchka added area/alerting Grafana Alerting area/provisioning triage/needs-confirmation used for OSS triage rotation - reported issue needs to be reproduced labels Jun 19, 2023
@armandgrillet armandgrillet added type/bug and removed triage/needs-confirmation used for OSS triage rotation - reported issue needs to be reproduced labels Jun 23, 2023
@armandgrillet
Copy link
Contributor

We have confirmed the bug. The substitution works for e.g. name but not for what is under settings.

@armandgrillet armandgrillet moved this to Backlog in Alerting Jun 23, 2023
@armandgrillet
Copy link
Contributor

@papagian
Copy link
Contributor

@armandgrillet I was able to reproduce the issue but I'm not sure how to fix this:
the error is returned inside grafana/alerting
because Config.ChatID is string and the value is an integer

The chatid value is correct (-808008888) here

alerting.AlertingFileV1

(*alerting.AlertingFileV1)(0x140033747e0)({
 configVersion: (alerting.configVersion) {
  APIVersion: (values.Int64Value) {
   value: (int64) 0,
   Raw: (string) ""
  }
 },
 Filename: (string) "",
 Groups: ([]alerting.AlertRuleGroupV1) <nil>,
 DeleteRules: ([]alerting.RuleDeleteV1) <nil>,
 ContactPoints: ([]alerting.ContactPointV1) (len=1 cap=1) {
  (alerting.ContactPointV1) {
   OrgID: (values.Int64Value) {
    value: (int64) 1,
    Raw: (string) (len=1) "1"
   },
   Name: (values.StringValue) {
    value: (string) (len=8) "Telegram",
    Raw: (string) (len=8) "Telegram"
   },
   Receivers: ([]alerting.ReceiverV1) (len=1 cap=1) {
    (alerting.ReceiverV1) {
     UID: (values.StringValue) {
      value: (string) (len=17) "telegram_notifier",
      Raw: (string) (len=17) "telegram_notifier"
     },
     Type: (values.StringValue) {
      value: (string) (len=8) "telegram",
      Raw: (string) (len=8) "telegram"
     },
     Settings: (values.JSONValue) {
      value: (map[string]interface {}) (len=2) {
       (string) (len=8) "bottoken": (string) "",
       (string) (len=6) "chatid": (int64) -808008888
      },
      Raw: (map[string]interface {}) (len=2) {
       (string) (len=8) "bottoken": (string) (len=15) "$TELEGRAM_TOKEN",
       (string) (len=6) "chatid": (string) (len=17) "$TELEGRAM_CHAT_ID"
      }
     },
     DisableResolveMessage: (values.BoolValue) {
      value: (bool) false,
      Raw: (string) ""
     }
    }
   }
  }
 },
 DeleteContactPoints: ([]alerting.DeleteContactPointV1) <nil>,
 Policies: ([]alerting.NotificiationPolicyV1) <nil>,
 ResetPolicies: ([]values.Int64Value) <nil>,
 MuteTimes: ([]alerting.MuteTimeV1) <nil>,
 DeleteMuteTimes: ([]alerting.DeleteMuteTimeV1) <nil>,
 Templates: ([]alerting.TemplateV1) <nil>,
 DeleteTemplates: ([]alerting.DeleteTemplateV1) <nil>
})

but it's transformed to string in transformInterface()

how do you suggest to catch this case? is there a reason that the Config.ChatID is string instead of integer?

@MikhailVorzhev
Copy link

Did you manage to solve the problem?
I have similar issue on version 10.x.x. Last working version 9.3.1.

NefixEstrada added a commit to NefixEstrada/grafana-alerting that referenced this issue Jun 5, 2024
With this commit, the ChatID and MessageThreadID configuration of the
Telegram notifier now can be configured either with a string or an
integer, without any breaking changes for anyone consuming this library
or the end users using it in their configuration files.

Fixes grafana/grafana#69950
@hassansaadat
Copy link

I have this issue in grafana 11.0.0 and managed to handle using this syntax:

  chatid: |
       $TELEGRAM_CHAT_ID

where $TELEGRAM_CHAT_ID is actual chat id (including starting -)

@MikhailVorzhev
Copy link

I have this issue in grafana 11.0.0 and managed to handle using this syntax:

  chatid: |
       $TELEGRAM_CHAT_ID

where $TELEGRAM_CHAT_ID is actual chat id (including starting -)

It's work for me too. Thanks

NefixEstrada added a commit to NefixEstrada/grafana-alerting that referenced this issue Oct 7, 2024
With this commit, the ChatID and MessageThreadID configuration of the
Telegram notifier now can be configured either with a string or an
integer, without any breaking changes for anyone consuming this library
or the end users using it in their configuration files.

Fixes grafana/grafana#69950
NefixEstrada added a commit to NefixEstrada/grafana-alerting that referenced this issue Oct 7, 2024
With this commit, the ChatID and MessageThreadID configuration of the
Telegram notifier now can be configured either with a string or an
integer, without any breaking changes for anyone consuming this library
or the end users using it in their configuration files.

Fixes grafana/grafana#69950
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backlog
Development

Successfully merging a pull request may close this issue.

6 participants