Fixed jobsprinters

This commit is contained in:
Zachary Gorman 2025-02-13 15:54:11 -08:00
parent 69f3146070
commit 31c72c9a6b
2 changed files with 323 additions and 328 deletions

View file

@ -226,7 +226,7 @@ $Headers = @{
$cmdbData = $Query.Value $cmdbData = $Query.Value
} else { } else {
$cmdbData = @{ $cmdbData = @{
Loc = "CMDB Mismatch!" SHS_LocationDetails = "CMDB Mismatch!"
Status = "CMDB Mismatch!" Status = "CMDB Mismatch!"
} }
} }
@ -234,7 +234,7 @@ $Headers = @{
#Write-Host $_.Exception.Message #Write-Host $_.Exception.Message
#Write-Warning "Failed querying Spark!" #Write-Warning "Failed querying Spark!"
$cmdbData = @{ $cmdbData = @{
Loc = "Failed querying Spark!" SHS_LocationDetails = "Failed querying Spark!"
Status = "Failed querying Spark!" Status = "Failed querying Spark!"
} }
} }

View file

@ -13,6 +13,15 @@ function Get-SHSPrinter {
[string]$printer [string]$printer
) )
# Spark connection params
$Tenant = 'https://samaritanhealth-amc.ivanticloud.com'
$Headers = @{
"Content-Type" = "application/json"
"Authorization" = 'rest_api_key=EB68123D62F8489295C807353C92D75B'
"Accept" = "*/*"
"Accept-Encoding" = "gzip, deflate, br"
}
Write-Progress -Activity "Getting printer details for $printer" -Status 'Getting IP Address' -PercentComplete 10 -ParentId 1 Write-Progress -Activity "Getting printer details for $printer" -Status 'Getting IP Address' -PercentComplete 10 -ParentId 1
$snmp = New-Object -ComObject olePrn.OleSNMP $snmp = New-Object -ComObject olePrn.OleSNMP
@ -32,7 +41,26 @@ function Get-SHSPrinter {
Write-Progress -Activity "Getting printer details for $printer" -Status 'Getting CMDB data' -PercentComplete 20 -ParentId 1 Write-Progress -Activity "Getting printer details for $printer" -Status 'Getting CMDB data' -PercentComplete 20 -ParentId 1
# $cmdbRecord = Get-LANDeskCMDBItem -Name $printer # $cmdbRecord = Get-LANDeskCMDBItem -Name $printer
$cmdbRecord = Search-ISMBO -BO cis -filter "Name eq '$Printer'" -RawFilter $timeout = if ($SparkQueryTimeoutSec) {$SparkQueryTimeoutSec} else {5}
$uri = "$Tenant/api/odata/businessobject/cis`?`$filter=Name eq '$printer'&`$top=1&`$skip=0"
try {
$Query = Invoke-RestMethod -Method GET -uri $uri -headers $Headers -TimeoutSec $timeout
if ($Query) {
$cmdbData = $Query.Value
} else {
$cmdbData = @{
SHS_LocationDetails = "CMDB Mismatch!"
Status = "CMDB Mismatch!"
}
}
} catch {
#Write-Host $_.Exception.Message
#Write-Warning "Failed querying Spark!"
$cmdbData = @{
SHS_LocationDetails = "Failed querying Spark!"
Status = "Failed querying Spark!"
}
}
$LocationConstructors = @( $LocationConstructors = @(
"SHS_AssetLocality", "SHS_AssetLocality",
@ -42,66 +70,76 @@ function Get-SHSPrinter {
"SHS_LocationDetails" "SHS_LocationDetails"
) )
$LocationData = Foreach ($Loc in $LocationConstructors) { $LocationData = Foreach($Loc in $LocationConstructors){
if ($Loc -eq 'SHS_Floor') { if ($Loc -eq 'SHS_Floor'){
$(if ($cmdbRecord.$Loc -match '-') { $cmdbRecord.$Loc.split('-')[-1] + " Floor" } else { $cmdbRecord.$Loc }) $(if ($cmdbData.$Loc -match '-'){$cmdbData.$Loc.split('-')[-1] + " Floor"} else{$cmdbData.$Loc})
} } elseif (![string]::IsNullOrEmpty($cmdbData.$Loc)){
elseif (![string]::IsNullOrEmpty($cmdbRecord.$Loc)) { $cmdbData.$Loc
$cmdbRecord.$Loc
} }
} }
$LocationData = $LocationData -join ' | ' $LocationData = $LocationData -join ' | '
# $locationData = $cmdbRecord.SHS_AssetLocality + " | " + $cmdbRecord.ivnt_Location + " | " + + " | " + $cmdbRecord.SHS_Department + " | " + $cmdbRecord.SHS_LocationDetails if ($cmdbData) {
# if($cmdbRecord.values._SHSLocation3.Length -gt $cmdbRecord.values._SHSCalcLocationString.Length){
# $locationData = $cmdbRecord.values._SHSLocation3
# }
# else{
# $locationData = $cmdbRecord.values._SHSCalcLocationString
# }
if ($cmdbRecord) {
# $CMDB_POA = $cmdbRecord.values._SHSPOANumber
# $CMDB_AssetTag = $cmdbRecord.values._SHSAssetTag
# $CMDB_Location = $locationData
# $CMDB_MAC = $cmdbRecord.values._SHSMACAddress
# $CMDB_model = $cmdbRecord.values._Model
# $CMDB_serial = $cmdbRecord.values._SerialNumber
# $CMDB_IP = $cmdbRecord.values._IPAddress
### Spark Properties ### Spark Properties
$CMDB_POA = $cmdbRecord.SHS_POANumber $CMDB_POA = $cmdbData.SHS_POANumber
$CMDB_AssetTag = $cmdbRecord.AssetTag $CMDB_AssetTag = $cmdbData.AssetTag
$CMDB_Location = $locationData $CMDB_Location = $locationData
$CMDB_MAC = $cmdbRecord.MACAddress $CMDB_MAC = $cmdbData.MACAddress
$CMDB_model = $cmdbRecord.Model $CMDB_model = $cmdbData.Model
$CMDB_serial = $cmdbRecord.SerialNumber $CMDB_serial = $cmdbData.SerialNumber
$CMDB_IP = $cmdbRecord.IPAddress $CMDB_IP = $cmdbData.IPAddress
$CMDB_Status = $cmdbData.Status
}
if ($null -eq $result.IPAddress) {
if ($CMDB_IP) {
$offlineIP = 'CMDB IP - ' + $CMDB_IP
} }
else { else {
$CMDB_POA = "*CMDB Mismatch - check CMDB*" $offlineIP = 'No DNS Entry'
$CMDB_AssetTag = "*CMDB Mismatch - check CMDB*" }
$CMDB_Location = "*CMDB Mismatch - check CMDB*" $props = [Ordered]@{
$CMDB_MAC = "*CMDB Mismatch - check CMDB*" Machine = $printer
$CMDB_model = "*CMDB Mismatch - check CMDB*" Status = 'No DNS Entry'
$CMDB_serial = "*CMDB Mismatch - check CMDB*" IP = $offlineIP
$CMDB_IP = "*CMDB Mismatch - check CMDB*" DomainName = 'No DNS Entry'
MAC = $CMDB_MAC
Model = $CMDB_model
Serial = $CMDB_serial
#Comment = $comment
Color = 'No DNS Entry'
Trays = 'No DNS Entry'
PageCount = 'No DNS Entry'
'CMDB POA' = $CMDB_POA
'CMDB AssetTag' = $CMDB_AssetTag
'CMDB Location' = $CMDB_Location
'CMDB Status' = $CMDB_Status
}
$obj = New-Object -TypeName PSObject -Property $props
return $obj
} }
if ($null -ne $result.IP) {
Write-Progress -Activity "Getting printer details for $name" -Status 'Connecting to printer' -PercentComplete 30 -ParentId 1 Write-Progress -Activity "Getting printer details for $name" -Status 'Connecting to printer' -PercentComplete 30 -ParentId 1
$printerip = $result.IP $printerip = $result.IPAddress
$domainName = $result.Path $null = $result.Name -match '[^.]*\.(.*)'
$domainName = $Matches[1]
#checks to see if the printer is online #checks to see if the printer is online
$online = Test-Connection $printerip -ErrorAction SilentlyContinue $online = Test-Connection $printerip -ErrorAction SilentlyContinue
if (-not $online) {
$status = "Offline"
if ($online) { $MAC = $CMDB_MAC
$model = $CMDB_model
$serial = $CMDB_serial
$color = "Offline"
$trays = "Offline"
$pagecount = "Offline"
}
else {
#opens snmp connection to the printer #opens snmp connection to the printer
$snmp.open($printerip, 'public', 2, 3000) $snmp.open($printerip, 'public', 2, 3000)
@ -348,15 +386,6 @@ function Get-SHSPrinter {
}#end if ($model) }#end if ($model)
} }
else {
$status = "Offline"
$MAC = $CMDB_MAC
$model = $CMDB_model
$serial = $CMDB_serial
$color = "Offline"
$trays = "Offline"
$pagecount = "Offline"
}
$props = [Ordered]@{ $props = [Ordered]@{
Machine = $printer Machine = $printer
@ -377,50 +406,16 @@ function Get-SHSPrinter {
'CMDB POA' = $CMDB_POA 'CMDB POA' = $CMDB_POA
'CMDB AssetTag' = $CMDB_AssetTag 'CMDB AssetTag' = $CMDB_AssetTag
'CMDB Location' = $CMDB_Location 'CMDB Location' = $CMDB_Location
'CMDB Status' = $CMDB_Status
} }
$obj = New-Object -TypeName PSObject -Property $props $obj = New-Object -TypeName PSObject -Property $props
$snmp.close() $snmp.close()
Write-Progress -Activity "Getting printer details for $name" -Completed Write-Progress -Activity "Getting printer details for $name" -Completed
return $obj return $obj
}#end if ($printerIp)
if ($CMDB_IP) {
$offlineIP = 'CMDB IP - ' + $CMDB_IP
}
else {
$offlineIP = 'No DNS Entry'
}
$props = [Ordered]@{
Machine = $printer
Status = 'No DNS Entry'
IP = $offlineIP
DomainName = 'No DNS Entry'
MAC = $CMDB_MAC
Model = $CMDB_model
Serial = $CMDB_serial
#Comment = $comment
Color = 'No DNS Entry'
Trays = 'No DNS Entry'
PageCount = 'No DNS Entry'
'CMDB POA' = $CMDB_POA
'CMDB AssetTag' = $CMDB_AssetTag
'CMDB Location' = $CMDB_Location
}
$obj = New-Object -TypeName PSObject -Property $props
$snmp.close()
return $obj
} }
function Get-PrinterIP {
param (
[parameter(ValueFromPipeline)]
[string]$printer
)
}
function Start-SHSPrinterWeb { function Start-SHSPrinterWeb {
param( param(
$printer $printer