# # # PowerShell 2 # # Send service and equipment data to ServiceView # # # URL to connect to ServiceView # $serviceview_api = "http:///put_services.php" # # The value of the SECRET option set in the options setup section. # $serviceview_secret = "" # # Build the connect URL # $url = "$($serviceview_api)?secret=$($serviceview_secret)" # # Load the JSON encoder/decoder # [System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions") $ser = New-Object System.Web.Script.Serialization.JavaScriptSerializer # # Create Web Client # $wc = New-Object Net.WebClient # # Connect to ServiceView and download the JSON # $data = @( @{"service_id"=""; "service_name"="Blackboard Application Servers"; "service_group_name"="Infrastructure"; "service_group_id"="6"; "description"="Blackboard Application Servers Infrastructure"; "catalogue_fg"="no"; "budget_owner"="Person"; "business_owner"="Person"; "technical_owner"="Person"; "service_code"=""; "supported_hours"="24x7"; "public_fg"="no"; "Cluster"="New Value2"; "equipment" = @( @{"hardware_id"="240"; "hardware_name"="bagpipes.soe.domain.com"; "service_id"="79"; "manufacturer"="Star"; "model"="Sunfire x4150"; "virtual_fg"="P"; "leased_fg"="Y"; "purchase_date"="2008-09-01"; "end_of_lease_date"="2011-08-01"; "end_of_maintenance_date"="2012-03-14"; "server_use"="Web Server"; "operating_system"="Red Hat Enterprise Linux 5"; "serial_number"="0825QAR112"; "asset_tag"="-"; "contract_id"="17063309"; "rack_units"="1"; "datacentre_id"="17"; "rack_id"="33"; "rack_position"="18"; "building_id"="0"; "floor"=""; "room"="" } # End of hardware hash @{"hardware_id"=""; "hardware_name"="bagpipes2.soe.domain.com"; "service_id"="79"; "manufacturer"="Bottom"; "model"="Sunfire x4150"; "virtual_fg"="P"; "leased_fg"="Y"; "purchase_date"="2008-09-01"; "end_of_lease_date"="2011-08-01"; "end_of_maintenance_date"="2012-03-14"; "server_use"="Web Server"; "operating_system"="Red Hat Enterprise Linux 5"; "serial_number"="0825QAR113"; "asset_tag"="-"; "contract_id"="17063309"; "rack_units"="1"; "datacentre_id"="17"; "rack_id"="33"; "rack_position"="18"; "building_id"="0"; "floor"=""; "room"="" } # End of 2nd hardware hash ) # End of equipment array "dependencies" = @( @{"service_id"="242"; "required_type_id"="1"; "cost_percent"="90"; "comment"="Required for service operation"; } # End of this dependency ) # End of dependency array } # end of service hash @{"service_id"=""; "service_name"="New Service"; "description"="New service description"; "catalogue_fg"="no"; "budget_owner"="Person"; "business_owner"="Person"; "technical_owner"="Person"; "service_code"="21897218627817298178219271"; "supported_hours"="24x7"; "public_fg"="no"; "Cluster"="Cluster1"; } # end of 2nd service hash @{"service_id"="12"; "action"="Delete"; } # end of delete service hash ) # end of data array # # Convert powerpoint array into JSON # $json = $ser.Serialize($data) # # Setup the POST values # $nvc = new-object System.Collections.Specialized.NameValueCollection $nvc.Add('data',$json) # # Create a web client object # $wc = new-object net.webclient # # Pass in URL and POST data # $webpage = $wc.UploadValues($url, $nvc) # # See what came back # $ret = [System.Text.Encoding]::ASCII.GetString($webpage) echo $ret