Set-UxLoggingLevel.ps1

Following on from my recent script set-uxfxscountry-ps1, here’s another quick script that uses Vik Jaswal’s great PowerShell module for the Sonus SBC1000 & 2000 gateways.

This one queries and displays on-screen the current logging level set in the gateway and lets you change the level of ALL of the components to a new value.

I decided I wanted a script to do this as my current Lync deployment project sees me debugging a collection of gateways, and several of them are VERY heavily loaded (with over 10 E1 ISDN channels active). When these are set to Trace, you really notice the performance hit in the UI, so whilst you might leave your average SBC 1000 set to Trace forever and not worry, these busier boxes don’t permit that luxury.

So, with a quick PS command I can ramp these to Trace, collect my logs and then drop them safely back to Default or Info.
 

 

From this…

…to this:

before after

 

Features

  • Confirms the gateway you’re connected to – exits with a warning if you’re not currently connected
  • PowerShell help and examples
  • Code-signed

You’re obviously welcome to build upon this. I considered adding a menu and more fine-grained control of logging subsystems and logs, but time got the better of me. I may revisit this later and add the ability to change the IP of a remote log server to that of your local client’s IP today.

Download

The meat of the script is below, or you can Download the whole shebang (including the certificate).

<#
.SYNOPSIS
This script changes the Log Level of all Subsystems in your Sonus/NET UX/SBC1000 or 2000 gateway.
It relies upon an established REST connection to your gateway &  Vik Jaswal's fantastic PowerShell
module for the Sonus UX/SBC: http://www.allthingsuc.co.uk/powershell-module-for-sonus-sbc-10002000/

.DESCRIPTION
I find it a tedious task to roller-coaster all of the monitoring SubSystems up and down during the
debugging process via the web ui.
This script will take ALL of your configured Subsystems and set them to the nominated level.
Run with no command-line parameters it will output the current state. (Yes, that probably breaches protocol).

.NOTES
Version                : 1.0
Date                : 9th April 2014
Gateway versions    : Tested on 3.0.2 & 3.1.1
Author                : Greig Sheridan
Revision History     :
v1.0    : 9th April 2014
.LINK
https://greiginsydney.com/Set-UxLoggingLevel-ps1

.EXAMPLE
.\Set-UxLoggingLevel.ps1
Description
-----------
With no command-line parameters, it will name the gateway you're connected to and output the current logging configuration.

.EXAMPLE
.\Set-UxLoggingLevel.ps1 Trace
Description
-----------
Sets the logging level of all Subsystems across ALL loggers to Trace.
Valid values are: Default, Trace, Debug, Info, Warn, Error, Fatal & Off.

.PARAMETER LogLevel
Valid values are: Default, Trace, Debug, Info, Warn, Error, Fatal & Off.

#>

[CmdletBinding(SupportsShouldProcess = $True)]
param(
[parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
[ValidateSet("Default", "Trace", "Debug", "Info", "Warn", "Error", "Fatal", "Off")]
[String]
$LogLevel=""
)

$LogLevelLookup = @{ "Default" = "0"; "Trace" = "1"; "Debug" = "2"; "Info" = "3"; "Warn" = "4"; "Error" = "5"; "Fatal" = "6"; "Off" = "7"}
$ReverseLogLevelLookup = @{ "0" = "Default" ; "1" = "Trace" ; "2" = "Debug"; "3" = "Info"; "4" = "Warn"; "5" = "Error"; "6" = "Fatal"; "7" = "Off"}

$LoggerNameLookup = @{ "com.sonus.sbc.ads" = "Active Directory Service"; "com.sonus.sbc.alarm" = "Alarm Service"; "com.sonus.sbc.mfg" = "Analog Manufacturing Test Tool";`
"com.sonus.sbc.bmp" = "BMP"; "com.sonus.sbc.cas" = "CAS Protocol"; "com.sonus.sbc.route" = "Call Routing Service"; "com.sonus.sbc.csm" = "Certificate Security Manager";`
"com.sonus.sbc.ccc" = "Common Call Control"; "com.sonus.sbc.trans" = "Common Transport Service"; "com.sonus.sbc.conf" = "Configuration System"; "com.sonus.sbc.zebos" = "Core Switching/Routing";`
"com.sonus.sbc.hosts" = "Hosts"; "com.sonus.sbc.isdn" = "ISDN Protocol"; "com.sonus.sbc.lic" = "License Management Service"; "com.sonus.sbc.log" = "Logging System";`
"com.sonus.sbc.msc" = "Media Stream Control Service"; "com.sonus.sbc.symsock" = "Network Services"; "com.sonus.sbc.osys" = "Operating System Logs";    "com.sonus.sbc.pmapi" = "Platform Management";`
"com.sonus.sbc.rad" = "Radius Manager Service";    "com.sonus.sbc.resrc" = "Resource Management"; "com.sonus.sbc.security" = "Security"; "com.sonus.sbc.sip" = "SIP Stack Service";`
"com.sonus.sbc.snmp" = "SNMP"; "com.sonus.sbc.watch" = "Statistics & Live Info Service"; "com.sonus.sbc.sba" = "Survivable Branch Appliance"; "com.sonus.sbc.shm" = "System Health Monitoring";`
"com.sonus.sbc.sysio" = "System I/O Service"; "com.sonus.sbc.stmr" = "System Timer Service"; "com.sonus.sbc.tip" = "Telephony Interface Process"; "com.sonus.sbc.trapd" = "Trap Service";`
"com.sonus.sbc.uas" = "User Authentication Service"}

$LogDestinationsLookup = @{"0" = "Local Log"}
$SubsystemTable = @()

#--------------------------------
# Are we connected? -------------
#--------------------------------
try
{
$NodeInfo = (get-uxsysteminfo)
write-output "We're connected to $($NodeInfo.NodeName).$($NodeInfo.DomainName)"
}
catch
{
write-warning "We're not connected to a gateway"
exit
}

#--------------------------------
# Get system logging *config* ---
#--------------------------------
$LogDestinations = (get-uxresource -resource "remotelog").remotelog_list
if ($LogDestinations.Count -eq 0)
{
write-warning "No Log destinations were found"
exit
}
#write-host "List has $($LogDestinations.Count) members"
foreach ($LogDestination in $LogDestinations.remotelog_pk)
{
$href = (get-uxresource -resource "remotelog/$($LogDestination.id)").remotelog
$LogDestinationsLookup.Add($LogDestination.id, $href.ServerAddress)
}

$list = (get-uxresource -resource "logger").logger_list
if ($list.Count -eq 0) {write-warning "No Subsystems were found"}
#write-host "List has $($list.Count) members"

#--------------------------------
# SET new logging values --------
#--------------------------------
if ($LogLevel -ne "")
{
foreach ($logger in $list)
{
foreach ($SubsystemName in $logger.logger_pk.id)
{
$command = "set-uxresource -resource ""logger/$SubsystemName"" -args ""LogLevel=$($LogLevelLookup.Get_Item($LogLevel))"""
try
{
$response = invoke-expression $command
}
catch
{
write-warning "Error caught by handler: $($_)"
}
}
}
}

#--------------------------------
# GET current logging values ----
#--------------------------------
foreach ($logger in $list)
{
foreach ($SubsystemName in $logger.logger_pk)
{
try
{
$href = (get-uxresource -resource "logger/$($SubsystemName.id)").logger
}
catch
{
write-warning "Error caught by handler: $($_)"
}
#Now create a custom object so we can output all this into a table:
$Properties  = @{Subsystem = $LoggerNameLookup.Get_Item($href.LoggerName); LogLevel = $ReverseLogLevelLookup.Get_Item($href.LogLevel); LogDest = $LogDestinationsLookup.Get_Item($href.LogDestination)}
$TableRow = new-object PSObject -Property $Properties
$SubsystemTable += $TableRow
}
}

#--------------------------------
# Display the output ------------
#--------------------------------

$myFormatShow = @{Expression={$_.Subsystem};Label="Subsystem";width=32}, `
@{Expression={$_.LogLevel};Label="Log Level";width=14}, `
@{Expression={$_.LogDest};Label="Log Destination";width=26}
$SubsystemTable | format-table $myFormatShow

 
 G.

Leave a Reply

Your email address will not be published. Required fields are marked *

... and please just confirm for me that you're not a bot first: Time limit is exhausted. Please reload the CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.