Ad Widget

Collapse

Access to chart2.php from Powershell in Zabbix v6 LTS

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • goran.q
    Junior Member
    • Nov 2021
    • 5

    #1

    Access to chart2.php from Powershell in Zabbix v6 LTS

    Hi,

    we are using Zabbix version 5 LTS and have reporting through Powershell which, among others, retrieve graphs as PNG files.
    Basically, we are authenticating on Zabbix server like this
    (we used this, but customized, script: https://gist.github.com/r-plus/0a2a4abd6c24eb647846)

    $authJSON = $baseJSON.clone();
    $authJSON.method = "user.login";
    $authJSON.params = @{ "user" = $zabbixServerUsernameInput; "password" = $zabbixServerPasswordInput };
    $login = Invoke-RestMethod -Uri $zabbixServerApiUrl -Body ($authJSON | ConvertTo-Json) -method POST -ContentType "application/json";

    and then use $login.result as cookie in session

    $zabbixDomain = $zabbixServerUrl;
    $session = New-Object -TypeName Microsoft.PowerShell.Commands.WebRequestSession;
    $cookie = New-Object -TypeName System.Net.Cookie;
    $cookie.Name = "zbx_sessionid";
    $cookie.Value = $login.result;
    $session.Cookies.Add($zabbixDomain, $cookie);

    This session works OK when accessing graph URL, for example

    Invoke-WebRequest -Uri http://IP-ADDRESS/zabbix/chart2.php?...ight=100&legen d=0&from=now-30d&to=now&profileIdx=web.graphs.filter -WebSession $session -Outfile $graphCurrentFile;

    When accessing graph URL with this session parameter, it is visible that new cookie is created (PHPSESSID) and everything works OK.
    This works fine in Zabbix 5 LTS.
    This does not work in Zabbix 6 LTS. In v6 we are getting "You are not logged in" response when accessing graph URL.

    When looking at cookies in v5, we have this (this works):

    $session.Cookies.GetCookies("http://IP-ADDRESS/zabbix")

    Comment :
    CommentUri :
    HttpOnly : True
    Discard : False
    Domain : IP-ADDRESS
    Expired : False
    Expires : 1.1.0001. 0:00:00
    Name : zbx_sessionid
    Path : /zabbix
    Port :
    Secure : False
    TimeStamp : 12.7.2023. 11:18:24
    Value : 5522f93476ba60eed3263ffb67eb22e
    Version : 0

    Comment :
    CommentUri :
    HttpOnly : True
    Discard : False
    Domain : IP-ADDRESS
    Expired : False
    Expires : 1.1.0001. 0:00:00
    Name : PHPSESSID
    Path : /zabbix
    Port :
    Secure : False
    TimeStamp : 12.7.2023. 9:51:14
    Value : sh5h52fgthz7qf5iiq03vp3f8f
    Version : 0

    When looking at cookies in v6, we have this (this does not work):

    $session.Cookies.GetCookies("http://IP-ADDRESS/zabbix")


    Comment :
    CommentUri :
    HttpOnly : False
    Discard : False
    Domain : IP-ADDRESS
    Expired : False
    Expires : 1.1.0001. 0:00:00
    Name : zbx_sessionid
    Path : /zabbix
    Port :
    Secure : False
    TimeStamp : 12.7.2023. 12:38:42
    Value : 39dafb464rft76299b7947ef9960497e
    Version : 0

    Comment :
    CommentUri :
    HttpOnly : True
    Discard : False
    Domain : IP-ADDRESS
    Expired : False
    Expires : 1.1.0001. 0:00:00
    Name : zbx_session
    Path : /zabbix
    Port :
    Secure : False
    TimeStamp : 12.7.2023. 12:38:54
    Value : eyJzZXNzaW9uaWQiOiI5YTMzftgrhZmZjA0OWVkNWZiMzMyMT ZjZTllYmE5ZiIsInNpZ24iOiIzYThhOGdrtbmkmI0ODczYmJl NjBkMmM5NjNkOGE1ODM1MzI4NGU5Y2EzY412OWRmYWRlNDQxMz FmYjc1NWY5In0%3D
    Version : 0

    Tried everything. At the end it looks to me that problem is with cookie format in versions 5 and 6, I am not sure.
    Documentation says that v6 uses cookie "stored as JSON encoded by base64", and v5 "a 32 character string".
    I did not succeed to convert this long cookie value from base64 in cookie Powershell (v7) can use in Invoke-WebRequest, and I am not even sure is that problem.

    So, my question at the end

    does anyone have solution to access zabbix 6 graph URL (eg http://IP-ADDRESS/zabbix/chart2.php?graphid=3004) from Powershell and authenticate any way (if not possible with cookie, then with user/password ...) and retrieve PNG.
    any suggestions are welcome

    Thank you
    Goran​
  • goran.q
    Junior Member
    • Nov 2021
    • 5

    #2
    I hope I am not only one in world with this problem... :-)
    I would really appreciate if someone have some hint.

    Thank you
    Goran

    Comment

    • sramil
      Junior Member
      • Oct 2023
      • 2

      #3
      Hi Goran, were you able to find a solution to this? I'm having the same issue.

      Comment

      • penguin_syan
        Junior Member
        • Mar 2024
        • 1

        #4
        Hi, I had the same issue.
        I'm not clear what happened, but like Goran said the problem is around the session and Cookie.
        I couldn’t reuse zbx_session (zbx_sessionid in Zabbix 5.0) with API and Console.

        Here is one of the solutions.
        I can get the graph’s PNG, when I log in to the Zabbix Console with Invoke-WebRequest and keep the session.

        Example code:


        May be too late to post this info, but I hope someone who has the same issue will be helpful.
        Finally, my English isn't that good, so thanks bear with me.

        Thank you.

        Comment

        Working...