ableev / Zabbix-in-Telegram

Zabbix Notifications with graphs in Telegram
MIT License
778 stars 233 forks source link

Media definition in zabbix and log trace for debug #3

Closed pizzulicchio closed 8 years ago

pizzulicchio commented 9 years ago

zabbixmedia Hi, What have i to insert into media configuration settings of zabbix, into "send to" field ?

The telephone number of recipient or what ? Can you post a screenshot or improve the documentation ?

and.... should be possible implement a sort of debug output of your script ? thank you very much! your idea to use telegram for notification is fantastic!

ableev commented 9 years ago

You should use nickname without "@" symbol. If your login is "@ableev" -> "ableev". Once you send something to bot, alert script will save your chatid.

Ok, I will improve the documentation and will try to add debug. But. You can test notification right in command line on zabbix server. I should give you an example :) I will.

pizzulicchio commented 9 years ago

have you got some tips for me? i have used my nickname in "send to" field but no notification arrive. how it's possible to debug?

ableev commented 9 years ago

Here my part of step-by-step solution on pure VPS.

Clone repo

git clone git@github.com:ableev/Zabbix-in-Telegram.git cd Zabbix-in-Telegram/

create zabbix user

and give him read-only access for all hosts / groups

create telegram bot, get token for it

I think you can do it if you are using the Telegram

fill in tg_vars.cfg

Clone tg_vars.cfg.example and change it. Use your TG api key and login/password for zabbix user, i.e.:

TG_KEY="101740052:AAEY2T_R7IJD_eYYPMDmoz80GKdqyyL8DCY"
ZBX_TG_PREFIX="zbxtg" 
ZBX_SERVER="http://zabbix.r1.zabbix.pro"
ZBX_API_USER="zbxapiusr886f4ec8dfefb88a94f40beaa88b26fa" 
ZBX_API_PASS="886f4ec8dfefb88a94f40beaa88b26fa886f4ec8dfefb88a94f40beaa88b26fa"
CURL="curl -s" 

Write something to bot

anything, literally.

Use your username without "@" symbol for test message

$ ./zbxtg.sh ableev test
{"ok":true,"result":{"message_id":4154,"from":{"id":321,"first_name":"Zabbix Bot","username":"Bot"},"chat":{"id":123,"first_name":"Ilya","last_name":"A","username":"ableev"},"date":1438123297,"text":"test\n\n--"}}

If it fails, you will see telegram api errors.


And if you didn't get any errors, maybe there are some mistakes in media/actions configuration in Zabbix.

pizzulicchio commented 9 years ago

ok, i'm going ahead... now i'm be able to receive telegram message with correct format data but i have no picture of the graph.

I receive an image with written : ERROR: No items definied.

screenshot_2015-07-29-01-18-28

Why ?

( thank you very much for your patience )

ableev commented 9 years ago

Could you please show me configuration of your action?

pizzulicchio commented 9 years ago

Sure: action Here a screen of Event in zabbix ( graph id seems to not been fetched ) event

ableev commented 9 years ago

I added new branch, could you, please, pull the latest code and checkout branch to "issues-3". Run zbxtg.sh with your data,

./zbxtg.sh "pizzulicchio" "PROBLEM test test test" "Last  value
zbxtg;graphs
zbxtg;graphs_period=10800
zbxtg;itemid:23924
zbxtg;title:Test test"

Note that zbxtg; strings must be on separate lines. It will print URL for zabbix web interface, you can open it in your browser. Is it valid or not?

pizzulicchio commented 9 years ago

Sure it's valid url, and itìs browseable. Here for you the output. debug

ableev commented 9 years ago

Looks like your zabbix's URL is different from config. I've just added -L option for curl. Could you pull the latest code and test again?

ableev commented 9 years ago

@pizzulicchio did that help?

pizzulicchio commented 9 years ago

Something is wrong. the output is:

debug2

nuved commented 9 years ago

I get this error, when I change method to image:

<!doctype html>
<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
        <title>Zabbix</title>
        <meta name="Author" content="Zabbix SIA" />
        <meta charset="utf-8" />
        <link rel="shortcut icon" href="images/general/zabbix.ico" />
<link rel="stylesheet" type="text/css" href="styles/default.css" />
<link rel="stylesheet" type="text/css" href="styles/color.css" />
<link rel="stylesheet" type="text/css" href="styles/icon.css" />
<link rel="stylesheet" type="text/css" href="styles/blocks.css" />
<link rel="stylesheet" type="text/css" href="styles/pages.css" />
<link rel="stylesheet" type="text/css" href="styles/themes/originalblue/main.css" />
<script>var PHP_TZ_OFFSET = 16200;</script><script src="js/browsers.js"></script>
<script src="jsLoader.php?ver=2.4.5&amp;lang=en_GB&showGuiMessaging=1"></script>
</head>
<body class="originalblue">
<div id="message-global-wrap"><div id="message-global"></div></div>
<div class="login">
    <div id="glow">
        <div class="loginForm">
            <div style="position: relative; color: #FFF; height: 100%;">
                <!-- Help & Support -->
                <div style="position: absolute; top: 0px; right: 10px;">
                    <a class="highlight" href="http://www.zabbix.com/documentation">Help</a>
                    &nbsp;|&nbsp;
                    <a class="highlight" href="https://support.zabbix.com">Support</a>
                </div>

                <!-- Copyright -->
                <div style="float: left; width: 250px; height: 100%;">
                    <div style="position: absolute; top: 39%; left: 30px;" class="loginLogo"></div>
                    <div style="position: absolute; bottom: 2px;">
                            <span class="bold textwhite" style="margin: 0 0 4px 4px; font-size: 0.9em;">
                                Zabbix 2.4.5 Copyright 2001-2015 by Zabbix SIA                          </span>
                    </div>
                </div>

                <!-- Login Form -->
                <div style="height: 100%; padding-top: 58px; padding-right: 40px; margin-left: 275px;">
                    <div style="float: right;">
                        <form action="index.php" method="post">
                            <input type="hidden" name="request" class="input hidden" value="" />
                            <ul style="list-style-type: none;">
                                <li style="padding-right: 6px; height: 22px;">
                                    <div class="ui-corner-all textwhite bold" style="padding: 2px 4px; float: right; background-color: #D60900; visibility: visible" >
                                        <span class="nowrap">Account is blocked for 18 seconds</span>
                                    </div>
                                </li>
                                <li style="margin-top: 10px; padding-top: 1px; height: 22px; width: 265px; white-space: nowrap;" >
                                    <div class="label">Username</div><input type="text" id="name" name="name" class="input" />
                                </li>
                                <li style="margin-top: 10px; padding-top: 1px; height: 22px; width: 265px; white-space: nowrap;" >
                                    <div class="label">Password</div><input type="password" id="password" name="password" class="input"/>
                                </li>
                                <li style="margin-top: 8px; text-align: center;">
                                    <input type="checkbox" id="autologin" name="autologin" value="1"  />
                                    <label for="autologin" class="bold" style="line-height: 20px; vertical-align: top;">
                                        Remember me for 30 days                                 </label>
                                    <div style="height: 8px;"></div>
                                    <input type="submit" class="input jqueryinput" name="enter" id="enter" value="Sign in" />
                                                                            <span style="margin-left: 14px;">
                                                <a class="highlight underline" href="dashboard.php">Login as Guest</a>
                                            </span>
                                                                    </li>
                            </ul>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    jQuery(document).ready(function() {
        jQuery('body').css('background-color', '#E8EAEF');
        jQuery('#enter').button();
        jQuery('#name').focus();
    });
</script>
<script type="text/javascript">
    jQuery(document).ready(function() {

        // the chkbxRange.init() method must be called after the inserted post scripts and initializing cookies
        cookie.init();
        chkbxRange.init();
    });
</script>
</body>
</html>
{"ok":false,"error_code":400,"description":"Error: PHOTO_INVALID_DIMENSIONS"}%      

from terminal i ran this command for testing it...

./zbxtg.sh "nuved" "PROBLEM test test test" "Last  value
zbxtg;graphs
zbxtg;graphs_period=10800
zbxtg;itemid:65440
zbxtg;title:Test test"
nuved commented 9 years ago

i find the problem... my password is so complicated and then it cant login to api zabbix suscessfully! i change my password and now everything is ok:D thx man

ableev commented 8 years ago

Probably that commit will fix the issue