Powershell, invoke-webrequest...and Zabbix -
i'm trying use powershell automate creation of reporting tool. need zabbix (v1.8) graph images. not yet possible through api must connect url , graphs.
this 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 have cookie set if ($sessionzabbix.cookies.count -eq 0) { write-host "fail connect" break } else {write-host "connected"} #now let's retrieve graph #4433 using priviously established session $graph = invoke-webrequest -uri ($zabbixgraphurl+"4433") -websession $sessionzabbix
i can connect , 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 , "content" idicates i'm not connected :
$graph.images.count 0 $graph.content [...] <span class="footer_sign">not connected</span>
anyone knows i've done wrong??
thanks
so got work : needed set cookie graph url using same sessionid :
$sessionzabbix.cookies.setcookies("http://zabfront-eqx.noc.lan/zabbix/chart2.php", $sessionzabbix.cookies.getcookieheader($zabbixloginurl))
Comments
Post a Comment