I'm trying to use powershell to automate the creation of a reporting tool. I need to get Zabbix (v1.8) graph images. As it is not yet possible through the API I must connect to the URL and then get the graphs.
This is my code :
$zabbixLoginUrl = "http://zabfront-eqx.noc.lan/zabbix/index.php?login=1"
$zabbixGraphUrl = "http://zabfront-eqx.noc.lan/zabbix/chart2.php?graphid="
$userName = "username"
$userPwd = "pwd"
$loginPostData = @{name=$userName;password=$userPwd;enter="Enter"}
$login = Invoke-WebRequest -Uri $zabbixLoginUrl -Method Post -Body $loginPostData -SessionVariable sessionZabbix
#let's see if we have a cookie set
if ($sessionZabbix.Cookies.Count -eq 0) {
Write-Host "fail to connect"
break
}
else {Write-Host "connected"}
#now let's retrieve the graph #4433 using the priviously established session
$graph = Invoke-WebRequest -Uri ($zabbixGraphUrl+"4433") -WebSession $sessionZabbix
I can connect and get a cookie :
$sessionZabbix.Cookies.GetCookies("http://zabfront-eqx.noc.lan/zabbix/index.php") | select name, value
Name Value
---- -----
zbx_sessionid b2451e6c7fd0767dec22cca46427b7c2
Unfortunatly $graph contains no "image" property and the "content" idicates that I'm not connected :
$graph.Images.Count
0
$graph.Content
[...]
<span class="footer_sign">Not connected</span>
Anyone knows what I've done wrong??
Thanks
SO I got it to work : I needed to set a cookie for the graph URL using the same sessionid :
$sessionZabbix.Cookies.SetCookies("http://zabfront-eqx.noc.lan/zabbix/chart2.php", $sessionZabbix.Cookies.GetCookieHeader($zabbixLoginUrl))