Skip to content

Commit 57383ef

Browse files
committed
New group/device/sensor creation
added new-prtggroup, new-prtgdevice, and updates to new-prtgsensor
1 parent e80be6d commit 57383ef

12 files changed

+269
-12
lines changed

buildmodule.ps1

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,18 @@ foreach ($l in $(ls $CmdletPath)) {
184184
###############################################################################
185185
# Add Helpers
186186

187-
$Output += $HelperFunctionHeader
188-
189-
foreach ($l in $(ls $HelperPath)) {
190-
$Contents = gc $l.FullName
191-
$Output += $FunctionHeader
192-
$Output += $l.BaseName
193-
$Output += "`r`n`r`n"
194-
$Output += [string]::join("`n",$Contents)
195-
$Output += "`r`n`r`n"
187+
if (Test-Path $HelperPath) {
188+
189+
$Output += $HelperFunctionHeader
190+
191+
foreach ($l in $(ls $HelperPath)) {
192+
$Contents = gc $l.FullName
193+
$Output += $FunctionHeader
194+
$Output += $l.BaseName
195+
$Output += "`r`n`r`n"
196+
$Output += [string]::join("`n",$Contents)
197+
$Output += "`r`n`r`n"
198+
}
196199
}
197200

198201
###############################################################################

prtgshell2.cs

5.86 KB
Binary file not shown.

prtgshell2.dll

1.5 KB
Binary file not shown.

prtgshell2.psd1

1.13 KB
Binary file not shown.

prtgshell2.psm1

1.85 KB
Binary file not shown.

src/cmdlets/New-PrtgDevice.ps1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
function New-PrtgDevice {
3+
Param (
4+
[Parameter(Mandatory=$True,Position=0)]
5+
[PrtgShell.PrtgDeviceCreator]$PrtgObject
6+
)
7+
8+
BEGIN {
9+
if (!($PrtgServerObject.Server)) { Throw "Not connected to a server!" }
10+
$PrtgServerObject.OverrideValidation()
11+
}
12+
13+
PROCESS {
14+
15+
$Url = $PrtgServerObject.UrlBuilder("adddevice2.htm")
16+
17+
HelperHTTPPostCommand $Url $PrtgObject.QueryString | Out-Null
18+
19+
}
20+
}

src/cmdlets/New-PrtgGroup.ps1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
function New-PrtgGroup {
3+
Param (
4+
[Parameter(Mandatory=$True,Position=0)]
5+
[PrtgShell.PrtgGroupCreator]$PrtgObject
6+
)
7+
8+
BEGIN {
9+
if (!($PrtgServerObject.Server)) { Throw "Not connected to a server!" }
10+
$PrtgServerObject.OverrideValidation()
11+
}
12+
13+
PROCESS {
14+
15+
$Url = $PrtgServerObject.UrlBuilder("addgroup2.htm")
16+
17+
HelperHTTPPostCommand $Url $PrtgObject.QueryString | Out-Null
18+
19+
}
20+
}

src/cmdlets/_helpers.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ function HelperHTTPPostCommand() {
7373

7474
if ( $url -and $data ) {
7575
[System.Net.WebRequest]$webRequest = [System.Net.WebRequest]::Create($url);
76+
7677
$webRequest.ServicePoint.Expect100Continue = $false;
78+
#$webRequest.MaximumAutomaticRedirections = 2;
79+
7780
if ( $credentials ) {
7881
$webRequest.Credentials = $credentials;
7982
$webRequest.PreAuthenticate = $true;

src/cs/NewPingSensor.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.IO;
3+
using System.Net;
4+
using System.Net.Security;
5+
using System.Security.Cryptography.X509Certificates;
6+
using System.Collections;
7+
using System.Collections.Generic;
8+
using System.Collections.Specialized;
9+
using System.Linq;
10+
using System.Web;
11+
using System.Xml;
12+
using System.Xml.Linq;
13+
14+
15+
16+
namespace PrtgShell {
17+
18+
public class NewPingSensor : PrtgSensorCreator {
19+
20+
public NewPingSensor () {
21+
this.sensortype = "ping";
22+
this.inherittriggers = true;
23+
this.name_ = "Ping";
24+
this.tags_ = new string[] {"prtgshell","pingsensor"};
25+
this.intervalgroup = true;
26+
this.interval = 30;
27+
}
28+
29+
public string QueryString {
30+
get {
31+
NameValueCollection queryString = System.Web.HttpUtility.ParseQueryString(string.Empty);
32+
33+
queryString["name_"] = this.name_;
34+
queryString["tags_"] = String.Join(" ",this.tags_);
35+
queryString["priority_"] = this.priority_.ToString();
36+
queryString["intervalgroup"] = Convert.ToString(Convert.ToInt32(this.intervalgroup));
37+
queryString["interval_"] = this.interval_;
38+
queryString["inherittriggers"] = Convert.ToString(Convert.ToInt32(this.inherittriggers));
39+
queryString["id"] = this.id.ToString();
40+
queryString["sensortype"] = this.sensortype;
41+
42+
return queryString.ToString();
43+
}
44+
}
45+
}
46+
}

src/cs/PrtgDeviceCreator.cs

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
using System;
2+
using System.IO;
3+
using System.Net;
4+
using System.Net.Security;
5+
using System.Security.Cryptography.X509Certificates;
6+
using System.Collections;
7+
using System.Collections.Generic;
8+
using System.Collections.Specialized;
9+
using System.Linq;
10+
using System.Web;
11+
using System.Xml;
12+
using System.Xml.Linq;
13+
14+
15+
16+
namespace PrtgShell {
17+
18+
19+
public class PrtgDeviceCreator {
20+
21+
public string name_ { get; set; }
22+
public string host_ { get; set; }
23+
public string[] tags_ { get; set; }
24+
public int id { get; set; }
25+
public string deviceicon_ { get; set; }
26+
//public int discoverytype_ = 0;
27+
//public int discoveryschedule_ = 0;
28+
29+
public string QueryString {
30+
get {
31+
NameValueCollection queryString = System.Web.HttpUtility.ParseQueryString(string.Empty);
32+
33+
queryString["id"] = this.id.ToString();
34+
queryString["name_"] = this.name_;
35+
queryString["host_"] = this.host_;
36+
queryString["deviceicon_"] = this.deviceicon_;
37+
queryString["tags_"] = String.Join(" ",this.tags_);
38+
//queryString["discoverytype_"] = Convert.ToString(Convert.ToInt32(this.discoverytype_));
39+
//queryString["discoveryschedule_"] = Convert.ToString(Convert.ToInt32(this.discoveryschedule_));
40+
41+
return queryString.ToString();
42+
}
43+
}
44+
45+
public PrtgDeviceCreator () {
46+
this.deviceicon_ = "a_server_1.png";
47+
this.tags_ = new string[] {""};
48+
}
49+
}
50+
}
51+
52+
/*
53+
54+
55+
56+
id:2517
57+
name_:DeviceName!
58+
ipversion_:0
59+
host_:google.com
60+
hostv6_:
61+
tags_:
62+
deviceicon_:a_server_1.png
63+
discoverytype_:0
64+
devicetemplate_:1
65+
devicetemplate_:1
66+
discoveryschedule_:0
67+
windowsconnection:0
68+
windowsconnection:1
69+
windowslogindomain_:
70+
windowsloginusername_:
71+
windowsloginpassword_:
72+
linuxconnection:0
73+
linuxconnection:1
74+
linuxloginusername_:
75+
linuxloginmode_:0
76+
linuxloginpassword_:
77+
privatekey_:
78+
wbemprotocol_:https
79+
wbemportmode_:0
80+
wbemport_:5989
81+
sshport_:22
82+
sshelevatedrights_:1
83+
elevationnamesudo_:
84+
elevationnamesu_:
85+
elevationpass_:
86+
sshversion_devicegroup_:2
87+
vmwareconnection:0
88+
vmwareconnection:1
89+
esxuser_:
90+
esxpassword_:
91+
esxprotocol_:0
92+
vmwaresessionpool_:1
93+
dbcredentials:0
94+
dbcredentials:1
95+
usedbcustomport_:0
96+
dbport_:
97+
dbauth_:0
98+
dbuser_:
99+
dbpassword_:
100+
dbtimeout_:60
101+
cloudcredentials:0
102+
cloudcredentials:1
103+
awsak_:
104+
awssk_:
105+
snmpversiongroup:0
106+
snmpversiongroup:1
107+
snmpversion_:V2
108+
snmpcommv1_:public
109+
snmpcommv2_:public
110+
snmpauthmode_:authpHMACMD596
111+
snmpuser_:
112+
snmpauthpass_:
113+
snmpencmode_:DESPrivProtocol
114+
snmpencpass_:
115+
snmpcontext_:
116+
snmpport_:161
117+
snmptimeout_:5
118+
accessgroup:0
119+
accessgroup:1
120+
accessrights_:1
121+
accessrights_:1
122+
accessrights_201:-1
123+
124+
*/

0 commit comments

Comments
 (0)