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
} else {
$cmdbData = @{
Loc = "CMDB Mismatch!"
SHS_LocationDetails = "CMDB Mismatch!"
Status = "CMDB Mismatch!"
}
}
@ -234,7 +234,7 @@ $Headers = @{
#Write-Host $_.Exception.Message
#Write-Warning "Failed querying Spark!"
$cmdbData = @{
Loc = "Failed querying Spark!"
SHS_LocationDetails = "Failed querying Spark!"
Status = "Failed querying Spark!"
}
}

View file

@ -13,6 +13,15 @@ function Get-SHSPrinter {
[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
$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
# $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 = @(
"SHS_AssetLocality",
@ -42,66 +70,76 @@ function Get-SHSPrinter {
"SHS_LocationDetails"
)
$LocationData = Foreach ($Loc in $LocationConstructors) {
$LocationData = Foreach($Loc in $LocationConstructors){
if ($Loc -eq 'SHS_Floor') {
$(if ($cmdbRecord.$Loc -match '-') { $cmdbRecord.$Loc.split('-')[-1] + " Floor" } else { $cmdbRecord.$Loc })
}
elseif (![string]::IsNullOrEmpty($cmdbRecord.$Loc)) {
$cmdbRecord.$Loc
if ($Loc -eq 'SHS_Floor'){
$(if ($cmdbData.$Loc -match '-'){$cmdbData.$Loc.split('-')[-1] + " Floor"} else{$cmdbData.$Loc})
} elseif (![string]::IsNullOrEmpty($cmdbData.$Loc)){
$cmdbData.$Loc
}
}
$LocationData = $LocationData -join ' | '
# $locationData = $cmdbRecord.SHS_AssetLocality + " | " + $cmdbRecord.ivnt_Location + " | " + + " | " + $cmdbRecord.SHS_Department + " | " + $cmdbRecord.SHS_LocationDetails
# 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
if ($cmdbData) {
### Spark Properties
$CMDB_POA = $cmdbRecord.SHS_POANumber
$CMDB_AssetTag = $cmdbRecord.AssetTag
$CMDB_POA = $cmdbData.SHS_POANumber
$CMDB_AssetTag = $cmdbData.AssetTag
$CMDB_Location = $locationData
$CMDB_MAC = $cmdbRecord.MACAddress
$CMDB_model = $cmdbRecord.Model
$CMDB_serial = $cmdbRecord.SerialNumber
$CMDB_IP = $cmdbRecord.IPAddress
$CMDB_MAC = $cmdbData.MACAddress
$CMDB_model = $cmdbData.Model
$CMDB_serial = $cmdbData.SerialNumber
$CMDB_IP = $cmdbData.IPAddress
$CMDB_Status = $cmdbData.Status
}
if ($null -eq $result.IPAddress) {
if ($CMDB_IP) {
$offlineIP = 'CMDB IP - ' + $CMDB_IP
}
else {
$CMDB_POA = "*CMDB Mismatch - check CMDB*"
$CMDB_AssetTag = "*CMDB Mismatch - check CMDB*"
$CMDB_Location = "*CMDB Mismatch - check CMDB*"
$CMDB_MAC = "*CMDB Mismatch - check CMDB*"
$CMDB_model = "*CMDB Mismatch - check CMDB*"
$CMDB_serial = "*CMDB Mismatch - check CMDB*"
$CMDB_IP = "*CMDB Mismatch - check CMDB*"
$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
'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
$printerip = $result.IP
$domainName = $result.Path
$printerip = $result.IPAddress
$null = $result.Name -match '[^.]*\.(.*)'
$domainName = $Matches[1]
#checks to see if the printer is online
$online = Test-Connection $printerip -ErrorAction SilentlyContinue
if ($online) {
if (-not $online) {
$status = "Offline"
$MAC = $CMDB_MAC
$model = $CMDB_model
$serial = $CMDB_serial
$color = "Offline"
$trays = "Offline"
$pagecount = "Offline"
}
else {
#opens snmp connection to the printer
$snmp.open($printerip, 'public', 2, 3000)
@ -348,15 +386,6 @@ function Get-SHSPrinter {
}#end if ($model)
}
else {
$status = "Offline"
$MAC = $CMDB_MAC
$model = $CMDB_model
$serial = $CMDB_serial
$color = "Offline"
$trays = "Offline"
$pagecount = "Offline"
}
$props = [Ordered]@{
Machine = $printer
@ -377,50 +406,16 @@ function Get-SHSPrinter {
'CMDB POA' = $CMDB_POA
'CMDB AssetTag' = $CMDB_AssetTag
'CMDB Location' = $CMDB_Location
'CMDB Status' = $CMDB_Status
}
$obj = New-Object -TypeName PSObject -Property $props
$snmp.close()
Write-Progress -Activity "Getting printer details for $name" -Completed
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 {
param(
$printer