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

Example of much less code for get_apppool.ps1 & get_sites.ps1 #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 3 additions & 23 deletions Zabbix_IIS8_monitoring/get_apppool.ps1
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
Import-Module WebAdministration
$apppool = Get-ChildItem -Path IIS:\Apppools -Name
$idx = 1
write-host "{"
write-host " `"data`":[`n"
foreach ($currentapppool in $apppool)
{
if ($idx -lt $apppool.count)
{

$line= "{ `"{#APPPOOL}`" : `"" + $currentapppool + "`" },"
write-host $line
}
elseif ($idx -ge $apppool.count)
{
$line= "{ `"{#APPPOOL}`" : `"" + $currentapppool + "`" }"
write-host $line
}
$idx++;
}
write-host
write-host " ]"
write-host "}"
$rawdata = Get-IISAppPool | select-object -property @{N='{#APPPOOL}';E={$_.Name}}
$jsondata = @{"data" = $rawdata}
$jsondata | ConvertTo-Json -Compress
19 changes: 16 additions & 3 deletions Zabbix_IIS8_monitoring/get_apppoolstate.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
param ([string] $name = 0)
Import-Module WebAdministration
param (
[string] $name = 0
)
$apppoolState = Get-WebAppPoolState -name "$name"
Write-Output ($apppoolState.value)

$ResultText = $apppoolState.Value
$ResultNumber = 99
#Valid values are Starting, Started, Stopping, Stopped, and Unknown.
$ResultNumber = switch ($ResultText) {
Starting { 0 }
Started { 1 }
Stopping { 2 }
Stopped { 3 }
Unknown { 4 }
Default { 99 }
}
$ResultNumber
26 changes: 3 additions & 23 deletions Zabbix_IIS8_monitoring/get_sites.ps1
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
Import-Module WebAdministration
$sites = Get-ChildItem -Path IIS:\Sites -Name
$idx = 1
write-host "{"
write-host " `"data`":[`n"
foreach ($currentsite in $sites)
{
if ($idx -lt $sites.count)
{

$line= "{ `"{#SITE}`" : `"" + $currentsite + "`" },"
write-host $line
}
elseif ($idx -ge $site.count)
{
$line= "{ `"{#SITE}`" : `"" + $currentsite + "`" }"
write-host $line
}
$idx++;
}
write-host
write-host " ]"
write-host "}"
$sites = Get-IISSite | select-object -property @{N='{#SITE}';E={$_.Name}}
$llddata = @{"data" = $sites}
$llddata | ConvertTo-Json -Compress
19 changes: 16 additions & 3 deletions Zabbix_IIS8_monitoring/get_sitestate.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
param ([string] $name = 0)
Import-Module WebAdministration
param (
[string] $name = 0
)
$siteState = Get-WebsiteState -name "$name"
Write-Output ($siteState.value)

$ResultText = $siteState.Value
$ResultNumber = 99
#Valid values are Starting, Started, Stopping, Stopped, and Unknown.
$ResultNumber = switch ($ResultText) {
Starting { 0 }
Started { 1 }
Stopping { 2 }
Stopped { 3 }
Unknown { 4 }
Default { 99 }
}
$ResultNumber