-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
Bulk Import #13
Comments
Hi @mkardos1, The first thing I did at my current job was write a script that reads a CSV and performs a bulk import of groups and devices, setting the location of each device! The following provides a sample of how this can be done Servers.csv
AddServers.ps1 if(!(Get-PrtgClient))
{
Connect-PrtgServer prtg.contoso.local
}
# Import the CSV
$csv = Import-Csv $PSScriptRoot\Servers.csv
# Group each record by its State
$states = $csv | group State
function ProcessStates($states) {
foreach($state in $states)
{
Write-Host "Processing state $($state.Name)"
# Get this state's PRTG Probe
$probe = Get-Probe $state.Name
if(!$probe)
{
throw "Could not find probe '$($state.Name)'"
}
# Group each record in this state by its District
$districts = $state.Group | group District
ProcessDistricts $probe $districts
}
}
function ProcessDistricts($probe, $districts) {
foreach($district in $districts)
{
Write-Host " Processing district $($district.Name)"
# Get this district's PRTG Group
$districtGroup = $probe | Get-Group $district.Name
if(!$districtGroup)
{
# If no such group exists, create one
$districtGroup = $probe | Add-Group $district.Name
}
ProcessOffices $district $districtGroup
}
}
function ProcessOffices($district, $districtGroup) {
foreach($office in $district.Group)
{
# Get this office's server
$device = $districtGroup | Get-Device $office.Name
if(!$device)
{
Write-Host " Adding device $($office.Name)"
# Add the device using a Host of <hostname>.<domain>
$device = $districtGroup | Add-Device $office.Name "$($office.Name).$env:userdnsdomain".ToLower()
# Set the location
$device | Set-ObjectProperty Location $office.Location
}
}
}
ProcessStates $states Note how I don't specify while($true) { Get-Device | where TotalSensors -eq 0 | Select -First 5 | Start-Autodiscovery; Sleep 300 } |
If not otherwise specified PrtgAPI assumes HTTPS Please try |
no luck.. when i enter wrong credentials, i receive message about it.. but once i enter correct credentials, i always receive SSL/TLS error.. i tried http://IP/, http://IP, 'http://IP', "http://IP".. no idea what to do :( |
It sounds like the issue is your PRTG Server has SSL enabled, however you are trying to connect via an IP Address. I was able to replicate the issue you are seeing by attempting to connect to my SSL PRTG Server by its IP Address instead of its DNS name It is not possible to securely connect to an HTTPS server via an IP Address. If you go to https://10.248.31.10 in your web browser you will likely receive a certificate error. When connecting via HTTP, PRTG will automatically redirect you to HTTPS since you have HTTPS enabled in your PRTG Config You either need to connect to your server via its DNS name your certificate is valid for, or modify PRTG to use HTTP instead if your environment has not been configured to use a proper hostname/SSL certificate for your server |
yep, there is https/ssl configured, but the server has no dns name / ssl certificate configured.. is there any way to accept the risk like with browser? |
As the default configuration of PRTG is to use HTTP, and there is no reason to have your PRTG Server configured with HTTPS if you do not intend to use a certificate, PrtgAPI does not allow ignoring SSL errors when connecting to servers. Since it appears there is no reason for your server to be using SSL, I recommend either switching it back to the default of HTTP or configuring a proper SSL certificate (even one signed by your domain's CA) + DNS name for your server |
Note: if for some reason you do wish to continue using HTTPS without being properly configured to do so, it is possible to instruct .NET to ignore SSL certificate errors, which will also affect PrtgAPI add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
Connect-PrtgServer https://10.248.31.10 However I strongly recommend modifying the config of your PRTG Server per above, as this technique will cause PowerShell to ignore all certificate errors from all HTTP/HTTPS requests for the life of the process |
thank you for all of your help!
but i need to specify: name (to be displayed), DNS name (instead of IP) and device template (created to use ping sensor).. without auto-discovery.. is there something like:
Another way how to ask this.. What objects are defined for class New-DeviceParameters? What can I specify? |
Hi @mkardos1, If you dump the object created by the C:\> $params = New-DeviceParameters dc-1
C:\> $params
Host : dc-1
IPVersion : IPv4
AutoDiscoveryMode : Manual
AutoDiscoverySchedule : Once
DeviceTemplates :
Name : dc-1
Tags : You can specify a HostName, FQDN, IPv4 or IPv6 address to the Also like in the PRTG UI, you can instruct your device parameters object to perform an auto-discovery using one or more device templates, retrieved via You will notice that in the PRTG UI when you create a new object you can specify all and every property at the time of creation, however for maintainability purposes, PrtgAPI only supports specifying a limited set of properties on For more information on modifying properties, see the wiki |
hi lordmilko, now i am facing issue with attaching a template to the device.. the way i am adding a device:
customTemplate includes only one sensor - ping.. however, the device added has no template, no sensor attached.. any idea why? |
If you run If you type Finally, if you type |
to answer your questions, yes, Get-DeviceTemplate returns the template, $param includes the template as well and it is also present in the url.. but ipversion_=0& |
once again, here is my code: $fqdn = $device.Name + ".nitra.jlrint.com" and here is the full URL from verbose VERBOSE: Performing the operation "Add-Device" on target "Device 1A (Host: ) (Destination: Zone 1 (ID: 6829))". |
That looks normal to me. The next thing to check is whether you can add the new device with these settings in PRTG, In the new device creation window, specify to perform an auto-discovery with a template, and then specify the SCtemplate. You should expect to see the same issue, You can then check the If you're able to add the device in PRTG but not PrtgAPI, if you can potentially run Fiddler and observe the difference in the TextView of the request against |
maaan, it is failing because i am trying to add unreal devices, hence are not reachable.. but whole idea of this script was to add devices which are not reachable so far.. |
or can i add those devices without auto-discovery, and just associate a ping sensor? |
You can't perform an auto-discovery on a device that is unreachable. As such, the behavior you are seeing is expected. As it appears your devices are successfully being added but those that are unreachable are not obtaining any sensors, this is also achieving the expected behavior If however, you would like to create a bunch of new devices and create some sensors on them regardless of whether or not they are available, you don't want to use auto-discovery for this. In this scenario, you have a couple of options
See the following wiki pages for more information on these topics |
The following is an example of how you might create a ping sensor from scratch on all of your newly created devices $pingParams = Get-Device -Id 40 | New-SensorParameters -RawType ping
$newDevices | Add-Sensor $pingParams |
You rock, lordmilko! I removed everything related to auto-discovery and used cloning ping sensor to the device i just created. Thanks for all your help. |
Hi @mkardos1, Glad to hear you got it working FYI, on a large install, when cloning there will be a delay while PrtgAPI waits for PRTG to completely create the object. If you don't need to manipulate the created object, you can speed up cloning requests by specifying If you have any further issues or questions feel free to open another issue! Regards, |
Bonjour @mkardos1 @lordmilko , je travaille dans une entreprise ou on utilise Nagios comme outils de supervision , maintenant on a va basculer en PRTG, et comme on a un peut prêt plus 500 équipement c'est difficile de les entrer manuellement, donc je voulez bien savoir comment intégrer un CSV qui contient une extraction des équipement du nagios en PRTG (Name, type équipement ou groupe, adresse ip). Merci d'avance. |
|
Hi,
I did a powershell script to import devices from the .csv file like the
attached one.
Imagine the zone is like a group of devices..
If you are interested, I can share it with you.
…--
Regards,
Martin
|
Yes, I'm interested, I'd like you to share it with me. Thank you. Regards
Le mer. 16 oct. 2019 à 13:04, mkardos1 <[email protected]> a écrit :
… Hi,
I did a powershell script to import devices from the .csv file like the
attached one.
Imagine the zone is like a group of devices..
If you are interested, I can share it with you.
--
Regards,
Martin
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#13?email_source=notifications&email_token=ANQCU2XKQY3YDDLHCG7NYRDQO3YL3A5CNFSM4E35V4L2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBMCPJA#issuecomment-542648228>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ANQCU2RHDKKRC2DDPIIY3MTQO3YL3ANCNFSM4E35V4LQ>
.
--
*Cdt*
*Mohammed BENSAID*
|
hi,
attahced is a script and an input file for your reference. script.txt - you
need to change to use the extension .ps1 as gmail is blocking executable
files.
also, you need to download a PrtgAPI to use the script. i believe, you can
google it..
it is a long time ago, so not sure what the script exactly does, because i
needed to edit it several times based on requirements..
you can use it as a starting point :)
enjoy
martin
st 16. 10. 2019 o 13:04 Martin Kardos <[email protected]>
napísal(a):
… Hi,
I did a powershell script to import devices from the .csv file like the
attached one.
Imagine the zone is like a group of devices..
If you are interested, I can share it with you.
--
Regards,
Martin
--
S pozdravom,
Martin Kardos
# Author: Martin Kardos
# Date: 25/04/2018
#
# This script was created to import devices into PRTG based on input csv file.
# It reads groups to which devices should be added and creates the group if not present already under staticaly defined parent group (Script123).
# Then reads devices and adds them to the monitoring if not present already. Device is added with staticaly define domain (.XXX.YYY.com) or with IP and the only sensor - ping.
#
# Possible issues:
# - ping sensor is cloned from the existing sensor with id 2048. If the sensor is removed from PRTG, sensor adding will fail.
# Possible improvements:
# - Domain, parent group specification in the input csv file.
# - Sensor association not depending on existing object.
#
# The author is not responsible for anything this script will cause to your PRTG.
# Use only if you know what your are doing. Use with caution. Live long and prosper.
Write-Host ""
Import-Module C:\PrtgAPI # imports PrtgAPI module to PowerShell
Write-Host " Module PrtgAPI imported."
if(!(Get-PrtgClient)) { # connects to the PRTG server if not already
Connect-PrtgServer ***SERVERNAME/IP*** (New-Credential ***USER*** ***PASSWORD***)
}
if(Get-PrtgClient) {
Write-Host " PRTG server connected."
} else {
throw "Error: Could not connect to the PRTG server!"
}
$ping = Get-Sensor -Id 2048 # gets ping sensor to be cloned, change this to the existing object id
$csv = Import-Csv $PSScriptRoot\input.csv # imports the CSV file
$zones = $csv | group Zone # groups records by zones
Write-Host " Input data loaded."
function ProcessZones($zones) { # processes zones
foreach($zone in $zones) {
Write-Host ""
Write-Host " ***** ZONE $($zone.Name) ******"
Write-Host ""
$group = Get-Group $zone.Name # checks for the group on server (group in PRTG = zone name)
if (!$group) { # if group does not exist in PRTG, creates one
Write-Host " Could not find group for zone $($zone.Name).. Creating.."
$parentgroup = Get-Group "Script123"
if (!$parentgroup) {
throw "Error: Could not find Script123 group!"
}
$group = $parentgroup | Add-Group $zone.Name # adds group
Write-Host " Group for zone $($zone.Name) created successfully."
} else {
Write-Host " Using existing group for zone $($zone.Name).."
}
$devices = $zone.Group | group Name # groups devices under the same zone
$ips = $zone.Group | group IP # groups IPs under the same zone
ProcessDevices $devices $ips $group
}
}
function ProcessDevices($devices, $ips, $group) { # processes devices
for($i=0; $i -lt $devices.Count; $i++) {
$dev = Get-Device $devices[$i].Name # checks for the device on server
if (!$dev) { # if the devices does not exist, creates one
#$fqdn = $device.Name + ".XXX.YYY.com" # prepares fqdn
$dev = $group | Add-Device $devices[$i].Name $ips[$i].Name # adds device with name and fqdn or IP
$ping | Clone-Object $dev.ID | Resume-Object # clones ping sensor to the device and resuming it
if ($dev) {
Write-Host " Device $($devices[$i].Name) successfully added."
} else {
Write-Host " Error: Device $($devices[$i].Name) not added."
}
} else {
Write-Host " Device $($ips[$i].Name) already exists, skipping.."
}
}
}
ProcessZones $zones # main function
Disconnect-PrtgServer # disconnects from the server
Write-Host ""
Write-Host " *****"
Write-Host ""
Write-Host " PRTG server disconnected."
Write-Host " Job done!"
Write-Host ""
# End of the script
|
hello,
thank you for your script, but I have not understood everything, please can
you help me I really need help on this subject, in fact what I'm looking
for is a script that adds them equipment based on three elements (Name,
type, ip address). Can you help me please .
Best regards
Le jeu. 17 oct. 2019 à 08:03, mkardos1 <[email protected]> a écrit :
… hi,
attahced is a script and an input file for your reference. script.txt - you
need to change to use the extension .ps1 as gmail is blocking executable
files.
also, you need to download a PrtgAPI to use the script. i believe, you can
google it..
it is a long time ago, so not sure what the script exactly does, because i
needed to edit it several times based on requirements..
you can use it as a starting point :)
enjoy
martin
st 16. 10. 2019 o 13:04 Martin Kardos ***@***.***>
napísal(a):
> Hi,
>
>
>
> I did a powershell script to import devices from the .csv file like the
> attached one.
>
> Imagine the zone is like a group of devices..
>
> If you are interested, I can share it with you.
>
> --
> Regards,
> Martin
>
--
S pozdravom,
Martin Kardos
# Author: Martin Kardos
# Date: 25/04/2018
#
# This script was created to import devices into PRTG based on input csv
file.
# It reads groups to which devices should be added and creates the group
if not present already under staticaly defined parent group (Script123).
# Then reads devices and adds them to the monitoring if not present
already. Device is added with staticaly define domain (.XXX.YYY.com) or
with IP and the only sensor - ping.
#
# Possible issues:
# - ping sensor is cloned from the existing sensor with id 2048. If the
sensor is removed from PRTG, sensor adding will fail.
# Possible improvements:
# - Domain, parent group specification in the input csv file.
# - Sensor association not depending on existing object.
#
# The author is not responsible for anything this script will cause to
your PRTG.
# Use only if you know what your are doing. Use with caution. Live long
and prosper.
Write-Host ""
Import-Module C:\PrtgAPI # imports PrtgAPI module to PowerShell
Write-Host " Module PrtgAPI imported."
if(!(Get-PrtgClient)) { # connects to the PRTG server if not already
Connect-PrtgServer ***SERVERNAME/IP*** (New-Credential ***USER***
***PASSWORD***)
}
if(Get-PrtgClient) {
Write-Host " PRTG server connected."
} else {
throw "Error: Could not connect to the PRTG server!"
}
$ping = Get-Sensor -Id 2048 # gets ping sensor to be cloned, change this
to the existing object id
$csv = Import-Csv $PSScriptRoot\input.csv # imports the CSV file
$zones = $csv | group Zone # groups records by zones
Write-Host " Input data loaded."
function ProcessZones($zones) { # processes zones
foreach($zone in $zones) {
Write-Host ""
Write-Host " ***** ZONE $($zone.Name) ******"
Write-Host ""
$group = Get-Group $zone.Name # checks for the group on server (group in
PRTG = zone name)
if (!$group) { # if group does not exist in PRTG, creates one
Write-Host " Could not find group for zone $($zone.Name).. Creating.."
$parentgroup = Get-Group "Script123"
if (!$parentgroup) {
throw "Error: Could not find Script123 group!"
}
$group = $parentgroup | Add-Group $zone.Name # adds group
Write-Host " Group for zone $($zone.Name) created successfully."
} else {
Write-Host " Using existing group for zone $($zone.Name).."
}
$devices = $zone.Group | group Name # groups devices under the same zone
$ips = $zone.Group | group IP # groups IPs under the same zone
ProcessDevices $devices $ips $group
}
}
function ProcessDevices($devices, $ips, $group) { # processes devices
for($i=0; $i -lt $devices.Count; $i++) {
$dev = Get-Device $devices[$i].Name # checks for the device on server
if (!$dev) { # if the devices does not exist, creates one
#$fqdn = $device.Name + ".XXX.YYY.com" # prepares fqdn
$dev = $group | Add-Device $devices[$i].Name $ips[$i].Name # adds device
with name and fqdn or IP
$ping | Clone-Object $dev.ID | Resume-Object # clones ping sensor to the
device and resuming it
if ($dev) {
Write-Host " Device $($devices[$i].Name) successfully added."
} else {
Write-Host " Error: Device $($devices[$i].Name) not added."
}
} else {
Write-Host " Device $($ips[$i].Name) already exists, skipping.."
}
}
}
ProcessZones $zones # main function
Disconnect-PrtgServer # disconnects from the server
Write-Host ""
Write-Host " *****"
Write-Host ""
Write-Host " PRTG server disconnected."
Write-Host " Job done!"
Write-Host ""
# End of the script
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#13?email_source=notifications&email_token=ANQCU2SIPFMLHNEJQUJBY5DQO754FA5CNFSM4E35V4L2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBO4Z6I#issuecomment-543018233>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ANQCU2U33SOJE3YXBDVKHNDQO754FANCNFSM4E35V4LQ>
.
--
*Cdt*
*Mohammed BENSAID*
|
PrtgAPI is a programming framework for developing custom applications for PRTG. Aided by the wiki, you are expected to apply yourself in order to achieve this goal, regardless of your level of programming experience. From what I'm seeing, it appears you have no interest in doing that, and you simply want someone to hand you a ready-to-go solution you can just run against your environment. You clearly haven't read any of the sample code that has been provided to you; if you had you would see that basically almost completely achieves what you're looking for. While I can't speak for @mkardos1, I am not going to develop your entire application for you. I encourage you to take this sample code and then read the wiki in order to make the additional adjustments you feel are required. If you then have a specific question you feel is not covered by the wiki, I'll be happy to help. |
Hello,
@lordmilko/PrtgAPI
<[email protected]>
Thank you for your reply, I never asked you to develop an application for
me, I asked @mkardos1 for an example so that I could be inspired to
reproduce my script. but thank you for the support.
Regards
Le jeu. 17 oct. 2019 à 23:50, lordmilko <[email protected]> a écrit :
… @mbensaid23 <https://github.com/mbensaid23>,
PrtgAPI is a programming framework for developing custom applications for
PRTG. Aided by the wiki <https://github.com/lordmilko/PrtgAPI/wiki>, you
are expected to apply yourself in order to achieve this goal, regardless of
your level of programming experience.
From what I'm seeing, it appears you have no interest in doing that, and
you simply want someone to hand you a ready-to-go solution you can just run
against your environment. You clearly haven't read any of the sample code
that has been provided to you; if you had you would see that basically
almost completely achieves what you're looking for.
While I can't speak for @mkardos1 <https://github.com/mkardos1>, I am not
going to develop your entire application for you. I encourage you to take
this sample code
<https://blog.paessler.com/how-to-add-hundreds-of-devices-to-prtg> and
then read the wiki <https://github.com/lordmilko/PrtgAPI/wiki> in order
to make the additional adjustments you feel are required.
If you then have a *specific* question you feel is *not* covered by the
wiki, I'll be happy to help.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#13?email_source=notifications&email_token=ANQCU2VDU4J55532LKI2JOTQPDM3ZA5CNFSM4E35V4L2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBRUJMI#issuecomment-543376561>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ANQCU2QQMDJZ2AI32JTUVV3QPDM3ZANCNFSM4E35V4LQ>
.
--
*Cdt*
*Mohammed BENSAID*
|
hi,
please contact me on my personal email - [email protected]
what do you mean by type? is it like some prtg object or type -
router/switch/etc ?
martin
|
Hello lordmilko,
Have you ever tried to make an import of devices into PRTG monitoring? I tried to use auto-discovery using a list of devices, but it adds reachable devices only. I'd like to add a list of devices, where both reachable and unreachable devs are added.
Thanks!
The text was updated successfully, but these errors were encountered: