Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seeking help for bulk creation of devices including ssl certificate sensor #373

Closed
2 tasks done
xinput opened this issue Dec 19, 2023 · 3 comments
Closed
2 tasks done
Labels
question Questions raised by people who don't know how to program or read the wiki :P

Comments

@xinput
Copy link

xinput commented Dec 19, 2023

What's going on?

Hello,

I'm currently struggling to find the right way to accomplish a bulk creation of devices and a ssl certificate sensor.

In generel I've used the script provided here #13 and modified it to my needs. It works pretty fine when it is executed without the sensor creation.

My csv file is pretty simple:

Name, Domain
domain.company.com, company.com

and my script looks like this:

if(!(Get-PrtgClient))
{
    Connect-PrtgServer prtg.company.com
}
 
# Import the CSV
$csv = Import-Csv "C:\Users\user\a-records.csv"
 
# Group each record by its Domain
$domains = $csv | group Domain
 
# Get this state's PRTG Probe
$probe = Get-Probe "prtg-probe"
 
function ProcessDomains($probe, $domains) {
 
    foreach($domain in $domains)
    {
        Write-Host "   Processing Domain $($domain.Name)"
 
        # Get this domain's PRTG Group
        $domainGroup = $probe | Get-Group $domain.Name
 
        if(!$domainGroup)
        {
            # If no such group exists, create one
            $domainGroup = $probe | Add-Group $domain.Name
        }
 
        ProcessArecords $domain $domainGroup
    }
}
 
function ProcessArecords($domain, $domainGroup) {
 
    foreach($arecord in $domain.Group)
    {
        # Get this office's server
        $device = $domaingroup | Get-Device $arecord.Name
 
        if(!$device)
        {
            Write-Host "      Adding device $($arecord.Name)"
 
            # Add the device using a Host of <hostname>.<domain>
            $device = $domainGroup | Add-Device $arecord.Name "$($arecord.Name).$env:userdnsdomain".ToLower()
 
        }
    }
}
 
ProcessDomains $probe $domains

so basically this script works well.

Let's assume I want to add the HTTP sensor I adjusted the command for the device creation to include the New-Sensor after a pipe:

 # Add the device using a Host of <hostname>.<domain> including HTTP sensor
 $device = $domainGroup | Add-Device $arecord.Name "$($arecord.Name)" | New-Sensor -http

This works also fine. Great.

Now There's the point where I'm struggeling. The sslcertificate sensor type.
I digged into the wiki but It seems I'm not able to find the right syntax to create the sslcertificate sensor on all newly created devices.

I appreciate any suggestion that helps me to solve this.

Due Dilligance

  • It wasn't covered by the wiki, I swear!
  • I have tried doing some basic research on this issue but haven't been able to come up with anything. Please help!
@xinput xinput added the question Questions raised by people who don't know how to program or read the wiki :P label Dec 19, 2023
@xinput
Copy link
Author

xinput commented Dec 19, 2023

Nevermind.
It was my bad, messed up the variables. Issue fixed. Please consider this as resolved

@xinput xinput closed this as completed Dec 19, 2023
@vegaobscura
Copy link

Hey @xinput , I'm actually running into the same issue and my code looks very similar. What variables did you correct/what ended up working?

Any help would be appreciated!

@xinput
Copy link
Author

xinput commented Dec 20, 2023

Hey @vegaobscura,

sure that's my adjusted function:

function ProcessArecords($domain, $domainGroup) {
 
    foreach($arecord in $domain.Group)
    {
        # Get this office's server
        $device = $domaingroup | Get-Device $arecord.Name
 
        if(!$device)
        {
            Write-Host "      Adding device $($arecord.Name)"
 
            # Add the device using a Host of <hostname>.<domain>
            $device = $domainGroup | Add-Device $arecord.Name "$($arecord.Name)"
       
            #Set Sensor Params for SSL Certificate Sensor
            $sslcertParams = $device | New-SensorParameters -RawType sslcertificate
 
            $device | Add-Sensor $sslcertParams
            $device | New-Sensor -http
        }
    }
}

the part that was added was this:

            #Set Sensor Params for SSL Certificate Sensor
            $sslcertParams = $device | New-SensorParameters -RawType sslcertificate
 
            $device | Add-Sensor $sslcertParams
            $device | New-Sensor -http

tested this yesterday and imported 800 devices with each a http and ssl certificate sensor. Took a while but worked flawlessly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Questions raised by people who don't know how to program or read the wiki :P
Projects
None yet
Development

No branches or pull requests

2 participants