Powershell, JSON and NoteProperty -


i'm trying use zabbix api powershell automate monitoring stuff. i'd retrieve "items" based on different parameters passed function : if -itemdescription parameter passed, description and/or if parameter -host passed limit scope host etc... can find method description here : https://www.zabbix.com/documentation/1.8/api/item/get

this correct request :

{ "jsonrpc":"2.0", "method":"item.get", "params":{     "output":"shorten",     "search": {"description": "apache"},     "limit": 10 }, "auth":"6f38cddc44cfbb6c1bd186f9a220b5a0", "id":2 } 

so, know how add several "params", did host.create method, :

$proxy = @{"proxyid" = "$proxyid"} $templates = @{"templateid" = "$templateid"} $groups = @{"groupid" = "$hostgroupid"} ... add-member -passthru noteproperty params @    {host=“$hostname”;dns="$hostfqdn";groups=$groups;templates=$templates;proxy_hostid=$proxyid} | ... 

what don't know how make conditional. can't find right syntax add "if" statement in middle of line. :

add-member -passthru noteproperty params @{output="extend";if(itemdescription) {search=$desctiption} } ) 

thanks lot guys!

also, pleaser pardon english, it's not 1st language

like kayasax, created "params" before passing add-member. fyi, woring code :

#construct params $params=@{} $search=@{} #construct "search" param if ($itemdescription -ne $null) {      $search.add("description", $itemdescription)     $params.add("search",$search) }  #contruct "host" param if ($hostname -ne $null) {$params.add("host", $hostname) }  #finish params $params.add("output", "extend") #construct json object   $objitem = (new-object psobject | add-member -passthru noteproperty jsonrpc '2.0' | add-member -passthru noteproperty method 'item.get' | add-member -passthru noteproperty params $params | add-member -passthru noteproperty auth $session.result | add-member -passthru noteproperty id '2') | convertto-json 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -