Windows client (powershell) script sending metric data to server has \r\n in stream


#1

I am having a strange problem. Windows client is version 19.1. I am running a powershell script that gathers data from exchange and should be sent to graphite. Problem is the data is getting broken up by \r\n somehow as you can see below. It seems like the \r\n insertions are coming after 79 characters. Is there a parameter or something that I am missing?

Here is the script:

$counters = @(

“\MSExchange ActiveSync\Requests/sec”,

“\MSExchange Database\Database Page Fault Stalls/sec”,

“\MSExchange Database\Database Cache Size”,

“\MSExchange Database\Log Record Stalls/sec”,

“\MSExchange Database\Log Threads Waiting/sec”,

“\MSExchange Database(Information Store)\Log Threads Waiting”,

“\MSExchangeIS Mailbox(_Total)\Messages Queued For Submission”,

“\MSExchangeIS Mailbox(*)\Messages Queued For Submission”,

“\MSExchange Database ==> Instances(*)\I/O Database Reads Average Latency”,

“\MSExchange Database ==> Instances(*)\I/O Database Writes Average Latency”,

“\MSExchangeIS Mailbox(_Total)\Messages Delivered/sec”,

“\MSExchangeIS Mailbox(_Total)\Messages Sent/sec”,

“\MSExchangeIS\User Count”

)

$unixEpochStart = new-object DateTime 1970,1,1,0,0,0,([DateTimeKind]::Utc)

$nowInSecconds = [int]([DateTime]::UtcNow - $unixEpochStart).TotalSeconds

(Get-counter -Counter $counters -MaxSamples 1).CounterSamples |

foreach {

      $location+"."+($_.Path.substring(2) -replace '[\)]', '.' -replace '[\. ]','_' -replace '[\\\(]', '.' -replace '%', 'pct' -replace 'i/o', 'io' -replace '/sec','_per_sec' -replace '/', '.' -replace '#', 'number' -replace ':', '_' -replace '_==>_instances','' -replace '_\.','.' -replace '__','_')  + " " + [System.Math]::Round($_.CookedValue,2) + " " +  [int][double]::Parse($nowInSecconds)

}

From the sensu-client.log file:

{“timestamp”:“2015-06-18T14:47:28.002681-0500”,“level”:“info”,“message”:“publishing check result”,“payload”:{“client”:“servername”,“check”:{“name”:“exchange-metrics”,“issued”:1434656845,“command”:“powershell.exe -ExecutionPolicy Unrestricted -f /etc/sensu/plugins/get-exchange-metrics.ps1 :::specifics.location:::”,“executed”:1434656845,“duration”:2.953,“output”:"[servername] Processing data from remote server failed with the following error \r\nmessage: The user “clientdomain.local/Computers/servername” isn’t assigned to any manage\r\nment roles. For more information, see the about_Remote_Troubleshooting Help top\r\nic.\r\n + CategoryInfo : OpenError: (System.Manageme…RemoteRunspace:Re \r\n moteRunspace) , PSRemotingTransportException\r\n + FullyQualifiedErrorId : PSSessionOpenFailed\r\nImport-PSSession : Cannot validate argument on parameter ‘Session’. The argumen\r\nt is null. Supply a non-null argument and try the command again.\r\nAt C:\etc\sensu\plugins\get-exchange-metrics.ps1:14 char:17\r\n+ Import-PSSession <<<< $Session\r\n + CategoryInfo : InvalidData: (:slight_smile: [Import-PSSession], ParameterBi \r\n ndingValidationException\r\n + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power \r\n Shell.Commands.ImportPSSessionCommand\r\n \r\nclient.servername.msexchange_rpcclientaccess.rpc_averaged_latency 4 1\r\n434656846\r\nclient.servername.msexchange_rpcclientaccess.rpc_operations_per_sec 0\r\n 1434656846\r\nclient.servername.msexchange_rpcclientaccess.rpc_requests 0 143465684\r\n6\r\nclient.servername.msexchange_rpcclientaccess.active_user_count 18 143\r\n4656846\r\nclient.servername.msexchange_rpcclientaccess.connection_count 44 1434\r\n656846\r\nclient.servername.msexchange_rpcclientaccess.user_count 23 1434656846\r\nclient.servername.msexchangeis.rpc_averaged_latency 2 1434656846\r\nclient.servername.msexchangeis.rpc_operations_per_sec 0 1434656846\r\nclient.servername.msexchangeis.rpc_requests 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_administrator.rpc_aver\r\nage_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_activesync.rpc_average\r\n_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_mailbox_event_based_as\r\nsistants.rpc_average_latency 2 1434656846\r\nclient.servername.msexchangeis_client.outlook_web_app.rpc_average_lat\r\nency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_pop-imap.rpc_average_l\r\natency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_transport.rpc_average_\r\nlatency 1 1434656846\r\nclient.servername.msexchangeis_client.other_clients.rpc_average_laten\r\ncy 0 1434656846\r\nclient.servername.msexchangeis_client.outlook_anywhere.rpc_average_la\r\ntency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_content_indexing.rpc_a\r\nverage_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_availability_service.r\r\npc_average_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_managed_custom_folder_\r\ncreation.rpc_average_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_management_task.rpc_av\r\nerage_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_monitoring_task.rpc_av\r\nerage_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_unified_messaging.rpc_\r\naverage_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_web_services.rpc_avera\r\nge_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_approval_api.rpc_avera\r\nge_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_mailbox_time_based_ass\r\nistants.rpc_average_latency 3 1434656846\r\nclient.servername.msexchangeis_client.exchange_rpc_service.rpc_averag\r\ne_latency 4 1434656846\r\nclient.servername.msexchangeis_client.exchange_transportsync_pm.rpc_a\r\nverage_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_mailbox_replication_se\r\nrvice.rpc_average_latency 0 1434656846\r\nclient.servername.msexchangeis_client.total.rpc_average_latency 10 1\r\n434656846\r\nclient.servername.msexchangeis_client.exchange_administrator.director\r\ny_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_activesync.directory_a\r\nccess_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_mailbox_event_based_as\r\nsistants.directory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.outlook_web_app.directory_acces\r\ns_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_pop-imap.directory_acc\r\ness_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_transport.directory_ac\r\ncess_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.other_clients.directory_access\r\nldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.outlook_anywhere.directory_acce\r\nss_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_content_indexing.direc\r\ntory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_availability_service.d\r\nirectory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_managed_custom_folder_\r\ncreation.directory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_management_task.direct\r\nory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_monitoring_task.direct\r\nory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_unified_messaging.dire\r\nctory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_web_services.directory\r\n_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_approval_api.directory\r\n_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_mailbox_time_based_ass\r\nistants.directory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_rpc_service.directory_\r\naccess_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_transportsync_pm.direc\r\ntory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_mailbox_replication_se\r\nrvice.directory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client._total.directory_access_ldap_re\r\nads_per_sec 0 1434656846\r\nclient.servername.msexchangeis.rpc_client_backoff_per_sec 0 143465684\r\n6\r\nThe term ‘Get-MailboxDatabase’ is not recognized as the name of a cmdlet, funct\r\nion, script file, or operable program. Check the spelling of the name, or if a \r\npath was included, verify that the path is correct and try again.\r\nAt C:\etc\sensu\plugins\get-exchange-metrics.ps1:44 char:34\r\n+ $MYDatabases =Get-MailboxDatabase <<<< -Status\r\n + CategoryInfo : ObjectNotFound: (Get-MailboxDatabase:String) , \r\n CommandNotFoundException\r\n + FullyQualifiedErrorId : CommandNotFoundException\r\n \r\nException calling “Substring” with “2” argument(s): “Index and length must refe\r\nr to a location within the string.\r\nParameter name: length”\r\nAt C:\etc\sensu\plugins\get-exchange-metrics.ps1:49 char:41\r\n+ $MyDriveString =$logPathString.substring <<<< (0,1);\r\n + CategoryInfo : NotSpecified: (:slight_smile: , MethodInvocationException\r\n + FullyQualifiedErrorId : DotNetMethodException\r\n \r\nException calling “Substring” with “2” argument(s): “Index and length must refe\r\nr to a location within the string.\r\nParameter name: length”\r\nAt C:\etc\sensu\plugins\get-exchange-metrics.ps1:50 char:38\r\n+ $MySubString=$logPathString.substring <<<< (0,2);\r\n + CategoryInfo : NotSpecified: (:slight_smile: , MethodInvocationException\r\n + FullyQualifiedErrorId : DotNetMethodException\r\n \r\nCannot convert argument “1”, with value: “\\\$”, for “Replace” to type “System.\r\nChar”: “Cannot convert value “\\\$” to type “System.Char”. Error: “String must \r\nbe exactly one character long.””\r\nAt C:\etc\sensu\plugins\get-exchange-metrics.ps1:52 char:40\r\n+ $Logfoldername = $logPathString.Replace <<<< ($MySubString,$UNCPath);\r\n + CategoryInfo : NotSpecified: (:slight_smile: , MethodException\r\n + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument\r\n \r\nYou cannot call a method on a null-valued expression.\r\nAt C:\etc\sensu\plugins\get-exchange-metrics.ps1:55 char:35\r\n+ $logfolderitems = $logfolder.items <<<< ()\r\n + CategoryInfo : InvalidOperation: (items:String) , RuntimeExce \r\n ption\r\n + FullyQualifiedErrorId : InvokeMethodOnNull\r\n \r\nclient.servername.exchange…log_count 1434656846\r\nCannot find an overload for “op_Subtraction” and the argument count: “2”.\r\nAt C:\etc\sensu\plugins\get-exchange-metrics.ps1:61 char:16\r\n+ $days = ($now - <<<< $DB.LastFullBackup).Days\r\n + CategoryInfo : NotSpecified: (:slight_smile: , MethodException\r\n + FullyQualifiedErrorId : MethodCountCouldNotFindBest\r\n \r\nclient.servername.exchange…days_since_backup 1434656846\r\nclient.servername.exchange…db_size 1434656846\r\nclient.servername.exchange.statistics.queued_messages 0 1434656846\r\n",“status”:0}}}


#2

Figured it out i think. Will post the code when i get back to my computer.

···

On Jun 18, 2015 3:16 PM, “David Kaminsky” dkamin5713@gmail.com wrote:

I am having a strange problem. Windows client is version 19.1. I am running a powershell script that gathers data from exchange and should be sent to graphite. Problem is the data is getting broken up by \r\n somehow as you can see below. It seems like the \r\n insertions are coming after 79 characters. Is there a parameter or something that I am missing?

Here is the script:

$counters = @(

“\MSExchange ActiveSync\Requests/sec”,

“\MSExchange Database\Database Page Fault Stalls/sec”,

“\MSExchange Database\Database Cache Size”,

“\MSExchange Database\Log Record Stalls/sec”,

“\MSExchange Database\Log Threads Waiting/sec”,

“\MSExchange Database(Information Store)\Log Threads Waiting”,

“\MSExchangeIS Mailbox(_Total)\Messages Queued For Submission”,

“\MSExchangeIS Mailbox(*)\Messages Queued For Submission”,

“\MSExchange Database ==> Instances(*)\I/O Database Reads Average Latency”,

“\MSExchange Database ==> Instances(*)\I/O Database Writes Average Latency”,

“\MSExchangeIS Mailbox(_Total)\Messages Delivered/sec”,

“\MSExchangeIS Mailbox(_Total)\Messages Sent/sec”,

“\MSExchangeIS\User Count”

)

$unixEpochStart = new-object DateTime 1970,1,1,0,0,0,([DateTimeKind]::Utc)

$nowInSecconds = [int]([DateTime]::UtcNow - $unixEpochStart).TotalSeconds

(Get-counter -Counter $counters -MaxSamples 1).CounterSamples |

foreach {

    $location+"."+($_.Path.substring(2) -replace '[\)]', '.' -replace '[\. ]','_' -replace '[\\\(]', '.' -replace '%', 'pct' -replace 'i/o', 'io' -replace '/sec','_per_sec' -replace '/', '.' -replace '#', 'number' -replace ':', '_' -replace '_==>_instances','' -replace '_\.','.' -replace '__','_')  + " " + [System.Math]::Round($_.CookedValue,2) + " " +  [int][double]::Parse($nowInSecconds)

}

From the sensu-client.log file:

{“timestamp”:“2015-06-18T14:47:28.002681-0500”,“level”:“info”,“message”:“publishing check result”,“payload”:{“client”:“servername”,“check”:{“name”:“exchange-metrics”,“issued”:1434656845,“command”:“powershell.exe -ExecutionPolicy Unrestricted -f /etc/sensu/plugins/get-exchange-metrics.ps1 :::specifics.location:::”,“executed”:1434656845,“duration”:2.953,“output”:"[servername] Processing data from remote server failed with the following error \r\nmessage: The user “clientdomain.local/Computers/servername” isn’t assigned to any manage\r\nment roles. For more information, see the about_Remote_Troubleshooting Help top\r\nic.\r\n + CategoryInfo : OpenError: (System.Manageme…RemoteRunspace:Re \r\n moteRunspace) , PSRemotingTransportException\r\n + FullyQualifiedErrorId : PSSessionOpenFailed\r\nImport-PSSession : Cannot validate argument on parameter ‘Session’. The argumen\r\nt is null. Supply a non-null argument and try the command again.\r\nAt C:\etc\sensu\plugins\get-exchange-metrics.ps1:14 char:17\r\n+ Import-PSSession <<<< $Session\r\n + CategoryInfo : InvalidData: (:slight_smile: [Import-PSSession], ParameterBi \r\n ndingValidationException\r\n + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power \r\n Shell.Commands.ImportPSSessionCommand\r\n \r\nclient.servername.msexchange_rpcclientaccess.rpc_averaged_latency 4 1\r\n434656846\r\nclient.servername.msexchange_rpcclientaccess.rpc_operations_per_sec 0\r\n 1434656846\r\nclient.servername.msexchange_rpcclientaccess.rpc_requests 0 143465684\r\n6\r\nclient.servername.msexchange_rpcclientaccess.active_user_count 18 143\r\n4656846\r\nclient.servername.msexchange_rpcclientaccess.connection_count 44 1434\r\n656846\r\nclient.servername.msexchange_rpcclientaccess.user_count 23 1434656846\r\nclient.servername.msexchangeis.rpc_averaged_latency 2 1434656846\r\nclient.servername.msexchangeis.rpc_operations_per_sec 0 1434656846\r\nclient.servername.msexchangeis.rpc_requests 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_administrator.rpc_aver\r\nage_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_activesync.rpc_average\r\n_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_mailbox_event_based_as\r\nsistants.rpc_average_latency 2 1434656846\r\nclient.servername.msexchangeis_client.outlook_web_app.rpc_average_lat\r\nency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_pop-imap.rpc_average_l\r\natency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_transport.rpc_average_\r\nlatency 1 1434656846\r\nclient.servername.msexchangeis_client.other_clients.rpc_average_laten\r\ncy 0 1434656846\r\nclient.servername.msexchangeis_client.outlook_anywhere.rpc_average_la\r\ntency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_content_indexing.rpc_a\r\nverage_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_availability_service.r\r\npc_average_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_managed_custom_folder_\r\ncreation.rpc_average_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_management_task.rpc_av\r\nerage_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_monitoring_task.rpc_av\r\nerage_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_unified_messaging.rpc_\r\naverage_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_web_services.rpc_avera\r\nge_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_approval_api.rpc_avera\r\nge_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_mailbox_time_based_ass\r\nistants.rpc_average_latency 3 1434656846\r\nclient.servername.msexchangeis_client.exchange_rpc_service.rpc_averag\r\ne_latency 4 1434656846\r\nclient.servername.msexchangeis_client.exchange_transportsync_pm.rpc_a\r\nverage_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_mailbox_replication_se\r\nrvice.rpc_average_latency 0 1434656846\r\nclient.servername.msexchangeis_client.total.rpc_average_latency 10 1\r\n434656846\r\nclient.servername.msexchangeis_client.exchange_administrator.director\r\ny_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_activesync.directory_a\r\nccess_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_mailbox_event_based_as\r\nsistants.directory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.outlook_web_app.directory_acces\r\ns_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_pop-imap.directory_acc\r\ness_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_transport.directory_ac\r\ncess_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.other_clients.directory_access\r\nldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.outlook_anywhere.directory_acce\r\nss_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_content_indexing.direc\r\ntory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_availability_service.d\r\nirectory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_managed_custom_folder_\r\ncreation.directory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_management_task.direct\r\nory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_monitoring_task.direct\r\nory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_unified_messaging.dire\r\nctory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_web_services.directory\r\n_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_approval_api.directory\r\n_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_mailbox_time_based_ass\r\nistants.directory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_rpc_service.directory_\r\naccess_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_transportsync_pm.direc\r\ntory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_mailbox_replication_se\r\nrvice.directory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client._total.directory_access_ldap_re\r\nads_per_sec 0 1434656846\r\nclient.servername.msexchangeis.rpc_client_backoff_per_sec 0 143465684\r\n6\r\nThe term ‘Get-MailboxDatabase’ is not recognized as the name of a cmdlet, funct\r\nion, script file, or operable program. Check the spelling of the name, or if a \r\npath was included, verify that the path is correct and try again.\r\nAt C:\etc\sensu\plugins\get-exchange-metrics.ps1:44 char:34\r\n+ $MYDatabases =Get-MailboxDatabase <<<< -Status\r\n + CategoryInfo : ObjectNotFound: (Get-MailboxDatabase:String) , \r\n CommandNotFoundException\r\n + FullyQualifiedErrorId : CommandNotFoundException\r\n \r\nException calling “Substring” with “2” argument(s): “Index and length must refe\r\nr to a location within the string.\r\nParameter name: length”\r\nAt C:\etc\sensu\plugins\get-exchange-metrics.ps1:49 char:41\r\n+ $MyDriveString =$logPathString.substring <<<< (0,1);\r\n + CategoryInfo : NotSpecified: (:slight_smile: , MethodInvocationException\r\n + FullyQualifiedErrorId : DotNetMethodException\r\n \r\nException calling “Substring” with “2” argument(s): “Index and length must refe\r\nr to a location within the string.\r\nParameter name: length”\r\nAt C:\etc\sensu\plugins\get-exchange-metrics.ps1:50 char:38\r\n+ $MySubString=$logPathString.substring <<<< (0,2);\r\n + CategoryInfo : NotSpecified: (:slight_smile: , MethodInvocationException\r\n + FullyQualifiedErrorId : DotNetMethodException\r\n \r\nCannot convert argument “1”, with value: “\\\$”, for “Replace” to type “System.\r\nChar”: “Cannot convert value “\\\$” to type “System.Char”. Error: “String must \r\nbe exactly one character long.””\r\nAt C:\etc\sensu\plugins\get-exchange-metrics.ps1:52 char:40\r\n+ $Logfoldername = $logPathString.Replace <<<< ($MySubString,$UNCPath);\r\n + CategoryInfo : NotSpecified: (:slight_smile: , MethodException\r\n + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument\r\n \r\nYou cannot call a method on a null-valued expression.\r\nAt C:\etc\sensu\plugins\get-exchange-metrics.ps1:55 char:35\r\n+ $logfolderitems = $logfolder.items <<<< ()\r\n + CategoryInfo : InvalidOperation: (items:String) , RuntimeExce \r\n ption\r\n + FullyQualifiedErrorId : InvokeMethodOnNull\r\n \r\nclient.servername.exchange…log_count 1434656846\r\nCannot find an overload for “op_Subtraction” and the argument count: “2”.\r\nAt C:\etc\sensu\plugins\get-exchange-metrics.ps1:61 char:16\r\n+ $days = ($now - <<<< $DB.LastFullBackup).Days\r\n + CategoryInfo : NotSpecified: (:slight_smile: , MethodException\r\n + FullyQualifiedErrorId : MethodCountCouldNotFindBest\r\n \r\nclient.servername.exchange…days_since_backup 1434656846\r\nclient.servername.exchange…db_size 1434656846\r\nclient.servername.exchange.statistics.queued_messages 0 1434656846\r\n",“status”:0}}}


#3

Here is the code I added to the powershell script. Fixed one problem, now on to the next problem.

$h = Get-Host

$buf = $h.UI.RawUI.BufferSize

$buf.Width = 300

$h.ui.rawui.BufferSize = $buf

$win = $h.UI.RawUI.WindowSize

$win.Width = 150

$h.ui.rawui.WindowSize = $win

···

On Thu, Jun 18, 2015 at 7:28 PM, David Kaminsky dkamin5713@gmail.com wrote:

Figured it out i think. Will post the code when i get back to my computer.

On Jun 18, 2015 3:16 PM, “David Kaminsky” dkamin5713@gmail.com wrote:

I am having a strange problem. Windows client is version 19.1. I am running a powershell script that gathers data from exchange and should be sent to graphite. Problem is the data is getting broken up by \r\n somehow as you can see below. It seems like the \r\n insertions are coming after 79 characters. Is there a parameter or something that I am missing?

Here is the script:

$counters = @(

“\MSExchange ActiveSync\Requests/sec”,

“\MSExchange Database\Database Page Fault Stalls/sec”,

“\MSExchange Database\Database Cache Size”,

“\MSExchange Database\Log Record Stalls/sec”,

“\MSExchange Database\Log Threads Waiting/sec”,

“\MSExchange Database(Information Store)\Log Threads Waiting”,

“\MSExchangeIS Mailbox(_Total)\Messages Queued For Submission”,

“\MSExchangeIS Mailbox(*)\Messages Queued For Submission”,

“\MSExchange Database ==> Instances(*)\I/O Database Reads Average Latency”,

“\MSExchange Database ==> Instances(*)\I/O Database Writes Average Latency”,

“\MSExchangeIS Mailbox(_Total)\Messages Delivered/sec”,

“\MSExchangeIS Mailbox(_Total)\Messages Sent/sec”,

“\MSExchangeIS\User Count”

)

$unixEpochStart = new-object DateTime 1970,1,1,0,0,0,([DateTimeKind]::Utc)

$nowInSecconds = [int]([DateTime]::UtcNow - $unixEpochStart).TotalSeconds

(Get-counter -Counter $counters -MaxSamples 1).CounterSamples |

foreach {

    $location+"."+($_.Path.substring(2) -replace '[\)]', '.' -replace '[\. ]','_' -replace '[\\\(]', '.' -replace '%', 'pct' -replace 'i/o', 'io' -replace '/sec','_per_sec' -replace '/', '.' -replace '#', 'number' -replace ':', '_' -replace '_==>_instances','' -replace '_\.','.' -replace '__','_')  + " " + [System.Math]::Round($_.CookedValue,2) + " " +  [int][double]::Parse($nowInSecconds)

}

From the sensu-client.log file:

{“timestamp”:“2015-06-18T14:47:28.002681-0500”,“level”:“info”,“message”:“publishing check result”,“payload”:{“client”:“servername”,“check”:{“name”:“exchange-metrics”,“issued”:1434656845,“command”:“powershell.exe -ExecutionPolicy Unrestricted -f /etc/sensu/plugins/get-exchange-metrics.ps1 :::specifics.location:::”,“executed”:1434656845,“duration”:2.953,“output”:"[servername] Processing data from remote server failed with the following error \r\nmessage: The user “clientdomain.local/Computers/servername” isn’t assigned to any manage\r\nment roles. For more information, see the about_Remote_Troubleshooting Help top\r\nic.\r\n + CategoryInfo : OpenError: (System.Manageme…RemoteRunspace:Re \r\n moteRunspace) , PSRemotingTransportException\r\n + FullyQualifiedErrorId : PSSessionOpenFailed\r\nImport-PSSession : Cannot validate argument on parameter ‘Session’. The argumen\r\nt is null. Supply a non-null argument and try the command again.\r\nAt C:\etc\sensu\plugins\get-exchange-metrics.ps1:14 char:17\r\n+ Import-PSSession <<<< $Session\r\n + CategoryInfo : InvalidData: (:slight_smile: [Import-PSSession], ParameterBi \r\n ndingValidationException\r\n + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power \r\n Shell.Commands.ImportPSSessionCommand\r\n \r\nclient.servername.msexchange_rpcclientaccess.rpc_averaged_latency 4 1\r\n434656846\r\nclient.servername.msexchange_rpcclientaccess.rpc_operations_per_sec 0\r\n 1434656846\r\nclient.servername.msexchange_rpcclientaccess.rpc_requests 0 143465684\r\n6\r\nclient.servername.msexchange_rpcclientaccess.active_user_count 18 143\r\n4656846\r\nclient.servername.msexchange_rpcclientaccess.connection_count 44 1434\r\n656846\r\nclient.servername.msexchange_rpcclientaccess.user_count 23 1434656846\r\nclient.servername.msexchangeis.rpc_averaged_latency 2 1434656846\r\nclient.servername.msexchangeis.rpc_operations_per_sec 0 1434656846\r\nclient.servername.msexchangeis.rpc_requests 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_administrator.rpc_aver\r\nage_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_activesync.rpc_average\r\n_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_mailbox_event_based_as\r\nsistants.rpc_average_latency 2 1434656846\r\nclient.servername.msexchangeis_client.outlook_web_app.rpc_average_lat\r\nency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_pop-imap.rpc_average_l\r\natency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_transport.rpc_average_\r\nlatency 1 1434656846\r\nclient.servername.msexchangeis_client.other_clients.rpc_average_laten\r\ncy 0 1434656846\r\nclient.servername.msexchangeis_client.outlook_anywhere.rpc_average_la\r\ntency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_content_indexing.rpc_a\r\nverage_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_availability_service.r\r\npc_average_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_managed_custom_folder_\r\ncreation.rpc_average_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_management_task.rpc_av\r\nerage_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_monitoring_task.rpc_av\r\nerage_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_unified_messaging.rpc_\r\naverage_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_web_services.rpc_avera\r\nge_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_approval_api.rpc_avera\r\nge_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_mailbox_time_based_ass\r\nistants.rpc_average_latency 3 1434656846\r\nclient.servername.msexchangeis_client.exchange_rpc_service.rpc_averag\r\ne_latency 4 1434656846\r\nclient.servername.msexchangeis_client.exchange_transportsync_pm.rpc_a\r\nverage_latency 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_mailbox_replication_se\r\nrvice.rpc_average_latency 0 1434656846\r\nclient.servername.msexchangeis_client.total.rpc_average_latency 10 1\r\n434656846\r\nclient.servername.msexchangeis_client.exchange_administrator.director\r\ny_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_activesync.directory_a\r\nccess_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_mailbox_event_based_as\r\nsistants.directory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.outlook_web_app.directory_acces\r\ns_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_pop-imap.directory_acc\r\ness_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_transport.directory_ac\r\ncess_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.other_clients.directory_access\r\nldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.outlook_anywhere.directory_acce\r\nss_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_content_indexing.direc\r\ntory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_availability_service.d\r\nirectory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_managed_custom_folder_\r\ncreation.directory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_management_task.direct\r\nory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_monitoring_task.direct\r\nory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_unified_messaging.dire\r\nctory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_web_services.directory\r\n_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_approval_api.directory\r\n_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_mailbox_time_based_ass\r\nistants.directory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_rpc_service.directory_\r\naccess_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_transportsync_pm.direc\r\ntory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client.exchange_mailbox_replication_se\r\nrvice.directory_access_ldap_reads_per_sec 0 1434656846\r\nclient.servername.msexchangeis_client._total.directory_access_ldap_re\r\nads_per_sec 0 1434656846\r\nclient.servername.msexchangeis.rpc_client_backoff_per_sec 0 143465684\r\n6\r\nThe term ‘Get-MailboxDatabase’ is not recognized as the name of a cmdlet, funct\r\nion, script file, or operable program. Check the spelling of the name, or if a \r\npath was included, verify that the path is correct and try again.\r\nAt C:\etc\sensu\plugins\get-exchange-metrics.ps1:44 char:34\r\n+ $MYDatabases =Get-MailboxDatabase <<<< -Status\r\n + CategoryInfo : ObjectNotFound: (Get-MailboxDatabase:String) , \r\n CommandNotFoundException\r\n + FullyQualifiedErrorId : CommandNotFoundException\r\n \r\nException calling “Substring” with “2” argument(s): “Index and length must refe\r\nr to a location within the string.\r\nParameter name: length”\r\nAt C:\etc\sensu\plugins\get-exchange-metrics.ps1:49 char:41\r\n+ $MyDriveString =$logPathString.substring <<<< (0,1);\r\n + CategoryInfo : NotSpecified: (:slight_smile: , MethodInvocationException\r\n + FullyQualifiedErrorId : DotNetMethodException\r\n \r\nException calling “Substring” with “2” argument(s): “Index and length must refe\r\nr to a location within the string.\r\nParameter name: length”\r\nAt C:\etc\sensu\plugins\get-exchange-metrics.ps1:50 char:38\r\n+ $MySubString=$logPathString.substring <<<< (0,2);\r\n + CategoryInfo : NotSpecified: (:slight_smile: , MethodInvocationException\r\n + FullyQualifiedErrorId : DotNetMethodException\r\n \r\nCannot convert argument “1”, with value: “\\\$”, for “Replace” to type “System.\r\nChar”: “Cannot convert value “\\\$” to type “System.Char”. Error: “String must \r\nbe exactly one character long.””\r\nAt C:\etc\sensu\plugins\get-exchange-metrics.ps1:52 char:40\r\n+ $Logfoldername = $logPathString.Replace <<<< ($MySubString,$UNCPath);\r\n + CategoryInfo : NotSpecified: (:slight_smile: , MethodException\r\n + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument\r\n \r\nYou cannot call a method on a null-valued expression.\r\nAt C:\etc\sensu\plugins\get-exchange-metrics.ps1:55 char:35\r\n+ $logfolderitems = $logfolder.items <<<< ()\r\n + CategoryInfo : InvalidOperation: (items:String) , RuntimeExce \r\n ption\r\n + FullyQualifiedErrorId : InvokeMethodOnNull\r\n \r\nclient.servername.exchange…log_count 1434656846\r\nCannot find an overload for “op_Subtraction” and the argument count: “2”.\r\nAt C:\etc\sensu\plugins\get-exchange-metrics.ps1:61 char:16\r\n+ $days = ($now - <<<< $DB.LastFullBackup).Days\r\n + CategoryInfo : NotSpecified: (:slight_smile: , MethodException\r\n + FullyQualifiedErrorId : MethodCountCouldNotFindBest\r\n \r\nclient.servername.exchange…days_since_backup 1434656846\r\nclient.servername.exchange…db_size 1434656846\r\nclient.servername.exchange.statistics.queued_messages 0 1434656846\r\n",“status”:0}}}