Skip to content

How to test script in command line

Ilya Ableev edited this page Oct 7, 2017 · 5 revisions

Note: Zabbix runs script with three parameters, so if you are going to run it without any, with one or with two, please, don't. In case of success you will see no errors and you will get your message.

If something won't be ok, additional info will appear in stdout.

Using sudo strongly required. Replace zabbix with zabbixsrv if you have that one on you server.

Testing simple text, private chats

linux-20fr:~/Zabbix-in-Telegram # sudo -u zabbix ./zbxtg.py "@username" test test
linux-20fr:~/Zabbix-in-Telegram #

If nothing happened

  • username is case sensitive
  • check that you sent message to the bot directly (one-to-one message)
  • check your connection to telegram api: curl https://api.telegram.org/bot${API_KEY}/getUpdates
  • if you see "User 'username' needs to send some text bot in private" that means that you hasn't sent message to your bot

Testing simple text, group chats

Make sure that you are using zbxtg_group.py for that if your zabbix version < 3.0

linux-20fr:~/Zabbix-in-Telegram # sudo -u zabbix ./zbxtg_group.py "Zabbix in Telegram" test test
linux-20fr:~/Zabbix-in-Telegram #

If nothing happened

  • if you have white spaces in your chat's name – use quotes
  • group chats don't have nicknames, use group's title to track you chat id automatically
  • if you see "You need to mention your bot in 'Group Name' group chat (i.e. type @YourBot)" that means that you hasn't mentioned you bot in your group chat

Testing graphs

Check you zbxtg_settings.py

linux-20fr:~/Zabbix-in-Telegram # sudo -u zabbix grep -E 'zbx_(server|api)' ./zbxtg_settings.py
zbx_server = "http://10.100.100.45/zabbix/" # zabbix server full url
zbx_api_user = "Admin"
zbx_api_pass = "zabbix"
zbx_api_verify = False  # True - do not ignore self signed certificates, False - ignore

Make sure that your zbx_server has correct url of zabbix ui. Fill in zbx_api_user and zbx_api_pass with valid account (if you don't have it, you can create new user with read-only rights). If your web ui available via https only and doesn't have valid certificate, change zbx_api_verify to False to ignore SSL errors.

linux-20fr:~/Zabbix-in-Telegram # sudo -u zabbix ./zbxtg.py ableev test "$(echo -e 'zbxtg;graphs: \nzbxtg;graphs_period=3600\nzbxtg;itemid:12345\nzbxtg;title:ololo')"
linux-20fr:~/Zabbix-in-Telegram #

Note: you can replace 12345 with real itemid (if you know something about it). If you don't have such itemid, you will see zbxtg.py: {u'error_code': 400, u'ok': False, u'description': u'[Error]: PHOTO_INVALID_DIMENSIONS'} and it's ok for now. In case you didn't fill correct url in config, you will see that error.

Validate server's URL

How to test if it's valid url or not? Just add /chart3.php to your URL:

linux-20fr:~/Zabbix-in-Telegram # curl -sI http://10.100.100.45/chart3.php | head -1
HTTP/1.1 404 Not Found

Not valid.

linux-20fr:~/Zabbix-in-Telegram # curl -sI http://localhost/chart3.php | head -1
HTTP/1.1 404 Not Found

Not valid.

linux-20fr:~/Zabbix-in-Telegram # curl -sI http://localhost/zabbix/chart3.php | head -1
HTTP/1.1 200 OK

Valid.

linux-20fr:~/Zabbix-in-Telegram # curl -sI http://10.100.100.45/zabbix/chart3.php | head -1
HTTP/1.1 200 OK

Valid.

So, you need to add http://localhost/zabbix/ or http://10.100.100.45/zabbix/ to your zbxtg_settings.py.