zevilz / zabbix-alertscript-telegram

Script for sending Zabbix alerts via Telegram bot (including sending native Zabbix graphs)
MIT License
19 stars 2 forks source link

Can't get Zabbix API auth token: Invalid parameter "/": unexpected parameter "user". #3

Closed seventhsite closed 1 year ago

seventhsite commented 1 year ago

Hi! Thank you for your script! I like it.

There is a problem in Zabbix 6.4. Zabbix Telegram alertscript: [ERROR] - Can't get Zabbix API auth token: Invalid parameter "/": unexpected parameter "user".

apparently the "user" parameter was deprecated in version 5.4. Support for it is dropped in 6.4, see [ZBXNEXT-8085]. Please update the API call in the script.

user was renamed to username

seventhsite commented 1 year ago

And other error in 6.4 which I don't realise yet.

Can't get graph image: graph not a PNG or you have no access to graph (graphData: graph:45981:2h:900:300; itemID: 45981; graphID: 2608)

I tried to remove all parameters from script URL, but it doesn't help. I can open a graph https://zabbix.example.com/chart2.php?graphid=2608 and see the PNG image. In script I chaged line 204 to

/usr/bin/curl -s -b "$ZABBIX_COOKIES_PATH" -c "$ZABBIX_COOKIES_PATH" -L -H 'Content-Type: image/png' -o "$GRAPH_PATH" "${ZABBIX_URL}/chart2.php?graphid=${ZABBIX_GRAPH_ID}"

but still got this error.

zevilz commented 1 year ago

@seventhsite i change deprecated parameter. Please, update the script and check second issue. Maybe it's related to the first issue.

seventhsite commented 1 year ago

@seventhsite i change deprecated parameter. Please, update the script and check second issue. Maybe it's related to the first issue.

Thank you for quick reaction! I changed the script on my side after I found the problem with user-username. But after it I gave the error about PNG. So, not - it is not related.

zevilz commented 1 year ago

@seventhsite you log in with the same user as in the script when you check the chart in the browser? You have a utility file in server? May you download graph from browser and check it by file utility:

file image.png
seventhsite commented 1 year ago

@zevilz yes I opened link in incognito and login with credentials from my script.

~/Downloads$ file chart2.png 
chart2.png: PNG image data, 1016 x 368, 8-bit/color RGB, non-interlaced

(Там ещё много изменений было, думаю что-то из этого влияет, но пока не могу понять что именно 6.2, 6.4)

zevilz commented 1 year ago

@seventhsite try to remove > /dev/null 2>/dev/null on 204 line and test sending on test mode in zabbix web interface.

seventhsite commented 1 year ago

Output is empty (only png error) even if I add -v to curl. Looks like somewhere else in script it forwarded to /dev/null.

I also tried

curl -v -s -b "/usr/lib/zabbix/alertscripts/zbx_cookies" -c "/usr/lib/zabbix/alertscripts/zbx_cookies" -L -H 'Content-Type: image/png' -o "/home/seventh/1.png" "https://zabbix.example.com/chart2.php?graphid=2608"

And got HTML document with error inside: You are not logged in. You must login to view this page.

Maybe something wrong with cookies... Screenshot from 2023-04-29 19-48-37

seventhsite commented 1 year ago

I tried in different ways, seem like cookie is ok. I think something changed in auth process in 6.4.

UPD: Maybe ZBXNEXT-8012 (Changes: user.checkAuthentication: added new parameter token)

zevilz commented 1 year ago

@seventhsite check what content in ZABBIX_WEB_AUTH var defined in line 186 (maybe they updated error message) then comment line 217 and check image in graph path

zevilz commented 1 year ago

@seventhsite error message not changed. You must disable deleting graph image in line 217 and check it (${GRAPHS_DIR}/graph_${ZABBIX_GRAPH_ID}_${CUR_TIME}.png). You successfully authorized but graph not an image.

seventhsite commented 1 year ago

Output is empty (only png error) even if I add -v to curl. Looks like somewhere else in script it forwarded to /dev/null.

My bad. I waited for lines in log.

check what content in ZABBIX_WEB_AUTH var defined in line 186

I made echo $ZABBIX_WEB_AUTH >> $SCRIPT_LOG_PATH on next line and see in log: </html>nter>nginx/1.18.0</center>enter>d>

comment line 217 and check image in graph path

I also commented block at 390. So graphs images is the html files with auth request

Screenshot from 2023-04-30 12-21-33

Now I think about </html>nter>nginx/1.18.0</center>enter>d> - looks like it is NGINX 403 Forbidden. I will research my NGINX config...

My logs now.

==> /var/log/zabbix/telegram_custom_script.log <==
[2023-04-30 12:31:44] Zabbix Telegram alertscript: [DEBUG] - current time: 1682850704; cookies expire time: 0; cookies modify time: 1682850693; cookies lifetime: 30; auth needed: 1
 </html>nter>nginx/1.18.0</center>enter>d>
[2023-04-30 12:31:44] Zabbix Telegram alertscript: [ERROR] - Can't get graph image: graph not a PNG or you have no access to graph (graphData: graph:45981:2h:900:300; itemID: 45981; graphID: 2608)
[2023-04-30 12:31:45] Zabbix Telegram alertscript: [ERROR] - Can't send graph: Bad Request: IMAGE_PROCESS_FAILED (chatID: 196755136; subject: ; itemID: 45981; graphID: 2608)
seventhsite commented 1 year ago

I was right. I added

allow 127.0.0.1;
allow MY_SERVER_IP;

in few sections of nginx zabbix.conf (IDK which one is needed) and now it work!

image

Thank you!