Ad Widget

Collapse

Zabbix and Telegram

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Maxz
    Junior Member
    • May 2015
    • 6

    #1

    Zabbix and Telegram

    Hello.
    I have this telegram.sh
    PHP Code:
    #!/bin/bash
    export to=$1;
    export subject=$2;
    export body=$3;
    bin/telegram-cli --U $USER -"msg $to $subject $body> /dev/null
    exit 
    If i execute this script from console, script successful work, but i add this script to zabbix, and want send messages from zabbix to telegram.
    That not work.
    I newbie in zabbix, if i can debug it. It must be useful.
    Thank you for any help.
  • Atsushi
    Senior Member
    • Aug 2013
    • 2028

    #2
    Please try write full path of telegram-cli in that script.

    Comment

    • Maxz
      Junior Member
      • May 2015
      • 6

      #3
      Originally posted by Atsushi
      Please try write full path of telegram-cli in that script.
      Sure man. This is of part of script.

      Full script that:
      PHP Code:
      #!/bin/bash
      export to=$1;
      export subject=$2;
      export body=$3;
      tgpath=/home/telegram/tg
      cd 
      ${tgpath}
      bin/telegram-cli --U $USER -"msg $to $subject $body> /dev/null
      exit 

      Comment

      • Atsushi
        Senior Member
        • Aug 2013
        • 2028

        #4
        Can you change directory to that directory(/home/telegram/tg) by zabbix user?
        The script and command are can execute by zabbix user?

        ex. execute commands by zabbix user
        # sudo -u zabbix <script name> <args>

        Comment

        • Maxz
          Junior Member
          • May 2015
          • 6

          #5
          Originally posted by Atsushi
          Can you change directory to that directory(/home/telegram/tg) by zabbix user?
          The script and command are can execute by zabbix user?

          ex. execute commands by zabbix user
          # sudo -u zabbix <script name> <args>
          Sure man. I can execute script from zabbix user and works correctly.

          Comment

          • Atsushi
            Senior Member
            • Aug 2013
            • 2028

            #6
            Have you set how and where to you as the setting of zabbix?

            Are you a registered telegram.sh as media?
            Do you have telegram.sh in the specified directory in AlertScriptsPath?

            Do not have been something in the log of Zabbix server?

            Comment

            • Maxz
              Junior Member
              • May 2015
              • 6

              #7
              Originally posted by Atsushi
              Have you set how and where to you as the setting of zabbix?

              Are you a registered telegram.sh as media?
              Do you have telegram.sh in the specified directory in AlertScriptsPath?

              Do not have been something in the log of Zabbix server?
              Zabbix settings and telegram ok.
              DebugLevel = 4

              I send any differnt way, from email and from telegram-cli.
              In a email message sent correctly.

              I cant find where and how have to look messages about sending emails or another script media.

              Comment

              • Colttt
                Senior Member
                Zabbix Certified Specialist
                • Mar 2009
                • 878

                #8
                if you have debug level 4; what say the log if zabbix-server run that script?
                Debian-User

                Sorry for my bad english

                Comment

                • Maxz
                  Junior Member
                  • May 2015
                  • 6

                  #9
                  Originally posted by Colttt
                  if you have debug level 4; what say the log if zabbix-server run that script?
                  Tell this :
                  PHP Code:
                  root@XX:/usr/share/zabbix/alertscripts# tailf /var/log/zabbix_server.log | tee /tmp/telegram_debug.log | grep -ni telegram
                  362213132:20150525:053047.925 In zbx_popen() command:'/usr/share/zabbix/alertscripts/telegram.sh "user#98764128" "Problem" "Problem"'
                  362813132:20150525:053047.933 telegram.sh output:
                  3630:Telegram-cli version 1.3.1Copyright (C2013-2015 Vitaly Valtman
                  3631
                  :Telegram-cli comes with ABSOLUTELY NO WARRANTY; for details type `show_license'.
                  3634:Telegram-cli uses libtgl version 2.0.1
                  3635:I: config dir=[/root/.telegram-cli]
                  3636:I: config_file=[/root/.telegram-cli/config]
                  7225: 13141:20150525:053202.449 In substitute_simple_macros() data:'/usr/share/zabbix/alertscripts/telegram.sh user#98764128 Hello'
                  7227: 13141:20150525:053202.449 In zbx_popen() command:'/usr/share/zabbix/alertscripts/telegram.sh user#98764128 Hello'
                  7238: 13141:20150525:053202.460 query [txnlev:1] [insert into alerts (alertid,actionid,eventid,clock,message,status,error,esc_step,alerttype) values (135,8,988,1432531922,':/usr/share/zabbix/alertscripts/telegram.sh user#98764128 Hello',1,'',1,1);
                  8012: 13132:20150525:053217.950 In zbx_popen() command:'/usr/share/zabbix/alertscripts/telegram.sh "user#98764128" "Problem" "Problem"'
                  8018: 13132:20150525:053217.962 telegram.sh output:
                  8020:Telegram-cli version 1.3.1, Copyright (C) 2013-2015 Vitaly Valtman
                  8021:Telegram-cli comes with ABSOLUTELY NO WARRANTY; for details type 
                  `show_license'.
                  8024:Telegram-cli uses libtgl version 2.0.1
                  8025:I: config dir=[/root/.telegram-cli]
                  8026:I: config_file=[/root/.telegram-cli/config] 

                  Comment

                  • Atsushi
                    Senior Member
                    • Aug 2013
                    • 2028

                    #10
                    Please show me more detail log.
                    you do not remove the information by grep so might contain important information.

                    Comment

                    • Maxz
                      Junior Member
                      • May 2015
                      • 6

                      #11
                      Originally posted by Atsushi
                      Please show me more detail log.
                      you do not remove the information by grep so might contain important information.
                      Thank you man.
                      I resolve problem with this guide.

                      Comment

                      • TripleX
                        Junior Member
                        • Mar 2016
                        • 3

                        #12
                        Question images/charts

                        i got everything up and running like a charm
                        error messages are coming in nicely incl last value etc.
                        however now i want to add images and then "automaticly" nothings gets pushed anymore
                        "Last value: {ITEM.LASTVALUE1} ({TIME})
                        zbxtg;graphs
                        zbxtg;graphs_period=10800
                        zbxtg;itemid:{ITEM.ID1}
                        zbxtg;title:{HOST.HOST} - {TRIGGER.NAME}"


                        when i do it from the command prompt

                        ./zbxtg.py xxxxx "test" "$(echo -e 'zbxtg;graphs: \nzbxtg;graphs_period=3600\nzbxtg;itemid:560\nzbxt g;titlelolo')"


                        Traceback (most recent call last):
                        File "./zbxtg.py", line 398, in <module>
                        main()
                        File "./zbxtg.py", line 380, in main
                        zbx.login()
                        File "./zbxtg.py", line 125, in login
                        requests.packages.urllib3.disable_warnings()
                        AttributeError: 'module' object has no attribute 'packages'


                        what am i doing wrong?

                        Comment

                        • Colttt
                          Senior Member
                          Zabbix Certified Specialist
                          • Mar 2009
                          • 878

                          #13
                          please try zbxtg.sh instead of zbxtg.py
                          Debian-User

                          Sorry for my bad english

                          Comment

                          • TripleX
                            Junior Member
                            • Mar 2016
                            • 3

                            #14
                            Thanx for the reply..

                            i changed the tg_vars.cfg
                            i ran the zbxtg.sh also made it chmod a+x
                            then basiscly ran the same command as with .py

                            however zbxtg.py --debug gave result
                            zbxtg.sh --debug was blanc
                            also without --debug blanc

                            the debug was also set in de log file for .py but not for the .sh file..
                            I have to dig in deeper tonight...

                            Comment

                            • TripleX
                              Junior Member
                              • Mar 2016
                              • 3

                              #15
                              Got it working

                              i got the error message " in private"
                              and went into telegram and sent bot a message /start

                              and i got the message in telegram inc the "url"

                              Comment

                              Working...