sync
This commit is contained in:
@@ -17,7 +17,7 @@ TPDT-535
|
|||||||
|
|
||||||
This procedure is used by Delphix to disable change tracking on every tables of a given db and schema
|
This procedure is used by Delphix to disable change tracking on every tables of a given db and schema
|
||||||
|
|
||||||
This is a wrapper around [hciTools].[dbo].[DBA_Change_Tracking_Maintenance] that refuses to enable maintenance mode on all tables directly.
|
This is a wrapper around [arizona].[dbo].[DBA_Change_Tracking_Maintenance] that refuses to enable maintenance mode on all tables directly.
|
||||||
*/
|
*/
|
||||||
CREATE PROCEDURE delphix.change_tracking_mgmt
|
CREATE PROCEDURE delphix.change_tracking_mgmt
|
||||||
@schema_name VARCHAR(100) = 'dbo'
|
@schema_name VARCHAR(100) = 'dbo'
|
||||||
|
|||||||
21
EXPLOIT - check if DbInitializationBackupPath2 exists.sql
Normal file
21
EXPLOIT - check if DbInitializationBackupPath2 exists.sql
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
INSERT INTO ActiveSystemServer.cfg.[Settings] ([ApplicationId],
|
||||||
|
[SettingId],
|
||||||
|
[SettingValue],
|
||||||
|
[SettingTypeName],
|
||||||
|
[SettingIsFavorite],
|
||||||
|
[SettingIsAdmin],
|
||||||
|
[SettingPredefinedValues],
|
||||||
|
[SettingDocumentation])
|
||||||
|
SELECT '57DDA4A4-5004-4458-A749-C01EA953FC4C' AS [ApplicationId],
|
||||||
|
'Values.Modules.Replication.DbInitializationBackupPath2' AS [SettingId],
|
||||||
|
'' AS [SettingValue],
|
||||||
|
'String' AS [SettingTypeName],
|
||||||
|
0 AS [SettingIsFavorite],
|
||||||
|
1 AS [SettingIsAdmin],
|
||||||
|
NULL AS [SettingPredefinedValues],
|
||||||
|
NULL AS [SettingDocumentation]
|
||||||
|
WHERE NOT EXISTS(
|
||||||
|
SELECT 1
|
||||||
|
FROM ActiveSystemServer.cfg.Settings s
|
||||||
|
WHERE s.[SettingId] = 'Values.Modules.Replication.DbInitializationBackupPath2'
|
||||||
|
)
|
||||||
26
EXPLOIT - find last snapshot in error.sql
Normal file
26
EXPLOIT - find last snapshot in error.sql
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
DECLARE @snapshot_in_error BIT = 0;
|
||||||
|
declare @today datetime = DATEADD(DAY,0,DATEDIFF(DAY,0,CURRENT_TIMESTAMP))
|
||||||
|
|
||||||
|
SELECT h.*
|
||||||
|
FROM msdb.dbo.sysjobs j
|
||||||
|
JOIN msdb.dbo.sysjobhistory h ON h.job_id = j.job_id
|
||||||
|
WHERE j.name ='D00480 - ActivePos_read Snapshot'
|
||||||
|
AND msdb.dbo.agent_datetime(h.run_date, h.run_time) > @today
|
||||||
|
AND h.run_status = 0 --there was an error
|
||||||
|
AND NOT EXISTS(
|
||||||
|
--there is not record not in error after the one found above
|
||||||
|
SELECT 1
|
||||||
|
FROM msdb.dbo.sysjobhistory h2
|
||||||
|
WHERE h2.job_id = h.job_id
|
||||||
|
AND msdb.dbo.agent_datetime(h2.run_date, h2.run_time) > msdb.dbo.agent_datetime(h.run_date, h.run_time)
|
||||||
|
AND h2.run_status <> 0
|
||||||
|
and h2.step_id = 0
|
||||||
|
)
|
||||||
|
ORDER BY h.run_time DESC ;
|
||||||
|
|
||||||
|
SELECT @snapshot_in_error = @@ROWCOUNT;
|
||||||
|
|
||||||
|
if @snapshot_in_error = 1
|
||||||
|
begin
|
||||||
|
exec msdb.dbo.sp_start_job @job_name='D00480 - ActivePos_read Snapshot'
|
||||||
|
end
|
||||||
14
EXPLOIT - test linked server azcash.sql
Normal file
14
EXPLOIT - test linked server azcash.sql
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
USE master
|
||||||
|
|
||||||
|
|
||||||
|
DECLARE @LinkedServerName NVARCHAR(128)='ARIZONACASH';
|
||||||
|
DECLARE @Result INT;
|
||||||
|
|
||||||
|
BEGIN TRY
|
||||||
|
EXEC @Result = sp_testlinkedserver @LinkedServerName;
|
||||||
|
PRINT 'Linked server is online.';
|
||||||
|
END TRY
|
||||||
|
BEGIN CATCH
|
||||||
|
PRINT 'Linked server is offline or does not exist.';
|
||||||
|
SELECT ERROR_MESSAGE();
|
||||||
|
END CATCH;
|
||||||
@@ -1,140 +0,0 @@
|
|||||||
Set-Location C:
|
|
||||||
$ErrorActionPreference = "Stop"
|
|
||||||
|
|
||||||
# VARIABLES
|
|
||||||
|
|
||||||
$query = "select SettingValue from cfg.Settings
|
|
||||||
where SettingId like 'Values.Modules.Replication.DbInitializationBackupPath%'
|
|
||||||
and len(SettingValue) > 1"
|
|
||||||
$erroronscript = 0
|
|
||||||
$errortext = ''
|
|
||||||
$snapshotLocation = ''
|
|
||||||
$snapshotHash =''
|
|
||||||
|
|
||||||
#Get configs from SQL
|
|
||||||
$connectionString = "Server='.\apssql';Database='ActiveSystemServer';Integrated Security=True;"
|
|
||||||
$connection = New-Object System.Data.SqlClient.SqlConnection
|
|
||||||
$connection.ConnectionString = $connectionString
|
|
||||||
$connection.Open()
|
|
||||||
$command = $connection.CreateCommand()
|
|
||||||
$command.CommandText = $query
|
|
||||||
$adapter = New-Object System.Data.sqlclient.sqlDataAdapter $command
|
|
||||||
$dataset = New-Object System.Data.DataSet
|
|
||||||
$adapter.Fill($dataSet) | Out-Null
|
|
||||||
$data = $dataset.Tables[0]
|
|
||||||
$workFolder=""
|
|
||||||
|
|
||||||
|
|
||||||
#get snapshot location
|
|
||||||
$results = Invoke-Sqlcmd -ServerInstance .\apssql -Database master -query "EXEC sp_helpdistributor"
|
|
||||||
$snapshotLocation = $results.directory
|
|
||||||
$workFolder = "$snapshotLocation\wrk_zip"
|
|
||||||
|
|
||||||
# Get database version
|
|
||||||
$query2 = "SELECT ActivePos_write.upd.DatabaseVersion()"
|
|
||||||
$command2 = New-Object System.Data.SqlClient.SqlCommand($query2,$connection)
|
|
||||||
|
|
||||||
$aposVersion = $command2.ExecuteScalar()
|
|
||||||
|
|
||||||
#create needed structure in c:\temp\work_repl
|
|
||||||
$snapshotLocalDirName = Get-ChildItem -Path $snapshotLocation\unc\*_ACTIVEPOSTRAN | Select-Object -ExpandProperty Name
|
|
||||||
New-Item -ItemType Directory -Force $workFolder\unc\$snapshotLocalDirName\$snapshotName
|
|
||||||
|
|
||||||
#let some time for the FS to settle, to avoid directory not found exceptions
|
|
||||||
start-sleep -Seconds 3
|
|
||||||
|
|
||||||
#find latest snapshot available
|
|
||||||
$snapshotName = Get-ChildItem -Path $snapshotLocation\unc\*_ACTIVEPOSTRAN\* | Sort-Object -Descending |Select-Object -First 1 -ExpandProperty Name
|
|
||||||
|
|
||||||
#copy latest snapshot to work folder
|
|
||||||
#copy-Item -Path "$snapshotLocation\unc\*_ACTIVEPOSTRAN\$snapshotName\*.*" -Destination "$workFolder\unc\$snapshotLocalDirName\$snapshotName\"
|
|
||||||
(Robocopy.exe $snapshotLocation\unc\*_ACTIVEPOSTRAN\$snapshotName\ $workFolder\unc\$snapshotLocalDirName\$snapshotName\ /MIR /R:3 /W:5)
|
|
||||||
|
|
||||||
#zip snapshot and folder structure
|
|
||||||
$compress = @{
|
|
||||||
Path = "$workFolder\unc"
|
|
||||||
CompressionLevel = "Fastest"
|
|
||||||
DestinationPath = "$workFolder\snapshot_$aposVersion.zip"
|
|
||||||
}
|
|
||||||
Compress-Archive @compress -Force
|
|
||||||
|
|
||||||
#compute CRC
|
|
||||||
$snapshotHash = Get-FileHash -Path $workFolder\snapshot_$aposVersion.zip -Algorithm SHA512 | Select-Object -ExpandProperty Hash | out-file -FilePath $workFolder\snapshot_$aposVersion.crc -Force
|
|
||||||
|
|
||||||
#delete work folder
|
|
||||||
Remove-Item $workFolder\unc -Force -Recurse
|
|
||||||
|
|
||||||
# Get backup directory
|
|
||||||
$query3 = "SELECT HCIP_value FROM HCITools.dbo.HCI_PARAMS WHERE HCIP_Key = 'BKP_DIR'"
|
|
||||||
$command3 = New-Object System.Data.SqlClient.SqlCommand($query3,$connection)
|
|
||||||
$source = $command3.ExecuteScalar()
|
|
||||||
|
|
||||||
$connection.close()
|
|
||||||
|
|
||||||
#copy every files to relevant shares
|
|
||||||
$jobs = foreach($dir in $data){
|
|
||||||
$logFile = $dir.SettingValue -replace "[\\]" , ""
|
|
||||||
$target = $dir.SettingValue
|
|
||||||
$logfile = "/log:`"c:\temp\$logFile.txt`""
|
|
||||||
$files = Get-ChildItem -Path $workFolder -Filter "snapshot*.*"
|
|
||||||
|
|
||||||
if(!(test-path "$Target")){
|
|
||||||
try{
|
|
||||||
New-Item -ItemType Directory -Force -Path $Target -ErrorAction Stop
|
|
||||||
}
|
|
||||||
catch{
|
|
||||||
$erroronscript = 1
|
|
||||||
if($errortext -eq ''){
|
|
||||||
$errortext = "Share is not reachable: $Target"
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
$errortext = $errortext + "`r`nShare is not reaechable: $Target"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(test-path "$Target"){
|
|
||||||
$files | ForEach-Object {
|
|
||||||
$testfile = $_.Directory
|
|
||||||
|
|
||||||
if(!(test-path $testfile)){
|
|
||||||
$erroronscript = 1
|
|
||||||
if($errortext -eq ''){
|
|
||||||
$errortext = "ActivePos_read file source is not accessible!"
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
$errortext = $errortext + "`r`nActivePos_read file source is not accessible!"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
start-job -ArgumentList $_.Directory, $target, $_.Name, $logFile -ScriptBlock{
|
|
||||||
param($source, $target, $testfile, $logFile )
|
|
||||||
$copy = robocopy $source $target $testfile /r:5 /w:120 $logFile
|
|
||||||
$LASTEXITCODE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$resultsjobs = Get-Job | Wait-Job | Receive-Job
|
|
||||||
|
|
||||||
foreach($resultjob in $resultsjobs){
|
|
||||||
if($resultjob -gt 7){
|
|
||||||
$errortext = "Robocopy exit code greater than 7!"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Remove-Job *
|
|
||||||
|
|
||||||
if (Test-Path 'C:\Temp\PScopy.ps1') { Remove-Item 'C:\Temp\PScopy.ps1' -Force }
|
|
||||||
|
|
||||||
#delete generated local files
|
|
||||||
$files | Remove-Item
|
|
||||||
|
|
||||||
#purge old version snapshots on the share
|
|
||||||
Get-ChildItem -Path $target -Filter "snapshot*.*" -Exclude "*$aposVersion*" | Remove-Item
|
|
||||||
|
|
||||||
IF($errortext -ne ''){ throw($errortext)}
|
|
||||||
|
|
||||||
28
TPDT-199/check_vesta_files.ps1
Normal file
28
TPDT-199/check_vesta_files.ps1
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
|
||||||
|
$query=@"
|
||||||
|
|
||||||
|
USE [ControlCenter]
|
||||||
|
DECLARE @res VARCHAR(MAX)=''
|
||||||
|
|
||||||
|
SELECT @res = @res + ',"'+[s].[SE_DNS]+'"'
|
||||||
|
FROM [dbo].[Server] s
|
||||||
|
JOIN [dbo].[Entity] e ON [e].[EN_id] = [s].[SE_entity]
|
||||||
|
WHERE e.[EN_id] IN (
|
||||||
|
1, --sun
|
||||||
|
2, --ama
|
||||||
|
21 --cvi
|
||||||
|
)
|
||||||
|
AND [s].[SE_DNS] NOT LIKE '%REF____.%'
|
||||||
|
AND (
|
||||||
|
s.[SE_end_prod_date] IS NULL
|
||||||
|
OR s.[SE_end_prod_date] > CURRENT_TIMESTAMP
|
||||||
|
)
|
||||||
|
ORDER BY s.[SE_entity], [s].[SE_OU_code];
|
||||||
|
|
||||||
|
SELECT STUFF(@res,1,1,'') as OU_list
|
||||||
|
|
||||||
|
"@
|
||||||
|
|
||||||
|
$machines = Invoke-Sqlcmd -ServerInstance HCIMON -Database ControlCenter -Query $query
|
||||||
|
|
||||||
|
$machines | Format-Table
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
@@ -0,0 +1,225 @@
|
|||||||
|
# Define the target SMB share and output CSV file
|
||||||
|
$targetMachine = ""
|
||||||
|
$targetShare = "" # Change this to the UNC path of your SMB share
|
||||||
|
$tcpPort = 1433 # Specify the port number to test (e.g., HTTP = 80, HTTPS = 443)
|
||||||
|
$rootDrive = "U:\" #root drive where files will be stored
|
||||||
|
$subFolder = "TPDT-676" #subfolder where all files will be stored on the $rootDrive
|
||||||
|
|
||||||
|
#ensure we have a working drive
|
||||||
|
if(-not(Test-Path -Path $rootDrive)){
|
||||||
|
$rootDrive = "D:\"
|
||||||
|
}
|
||||||
|
|
||||||
|
#create the destination folder if missing
|
||||||
|
$dest = "$rootDrive\$subFolder".Replace("\\","\")
|
||||||
|
if (-not (Test-Path -Path $dest)) {
|
||||||
|
New-Item -ItemType Directory -Path $dest
|
||||||
|
}
|
||||||
|
|
||||||
|
$outputCsvLAT = "$dest\tpdt-676-POS2.csv" #name of the csv file with the results
|
||||||
|
$logFile = "$dest\tpdt-676-POS2.log" #place of log file (for debugging sql job)
|
||||||
|
|
||||||
|
$maxFiles = 3 #how many csv file we keep after doing a rotation
|
||||||
|
$maxFileSizeMB = 10 #What is the max size of a csv file before we do a rotation in MB
|
||||||
|
$testCount = 5 # Number of connection attempts per iteration
|
||||||
|
|
||||||
|
# Function to check the size of the CSV file
|
||||||
|
function Check-CsvFileSize {
|
||||||
|
param ($filePath)
|
||||||
|
|
||||||
|
if (Test-Path $filePath) {
|
||||||
|
$fileSizeMB = (Get-Item $filePath).length / 1MB
|
||||||
|
return $fileSizeMB
|
||||||
|
} else {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to rotate files
|
||||||
|
function Rotate-CsvFile {
|
||||||
|
param ($filePath, $rotationPath, $maxFiles)
|
||||||
|
|
||||||
|
#trailing backslash needed for concatenation of the path
|
||||||
|
if (-not $rotationPath.EndsWith("\")) {
|
||||||
|
$rotationPath += "\"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create rotation directory if it doesn''t exist
|
||||||
|
if (-not (Test-Path $rotationPath)) {
|
||||||
|
New-Item -ItemType Directory -Path $rotationPath
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get the current timestamp to append to the rotated filename
|
||||||
|
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
|
||||||
|
$fileName = [System.IO.Path]::GetFileNameWithoutExtension($filePath)
|
||||||
|
$fileExtension = [System.IO.Path]::GetExtension($filePath)
|
||||||
|
|
||||||
|
# Generate new rotated filename
|
||||||
|
$rotatedFileName = "$rotationPath$fileName-$timestamp$fileExtension"
|
||||||
|
|
||||||
|
# Rotate the file
|
||||||
|
Rename-Item -Path $filePath -NewName $rotatedFileName
|
||||||
|
|
||||||
|
# Get all rotated files sorted by creation time
|
||||||
|
$rotatedFiles = Get-ChildItem -Path $rotationPath -Filter "$fileName-*$fileExtension" | Sort-Object LastWriteTime -Descending
|
||||||
|
|
||||||
|
# Keep only the most recent 3 files
|
||||||
|
$filesToDelete = $rotatedFiles | Select-Object -Skip $maxFiles
|
||||||
|
foreach ($file in $filesToDelete) {
|
||||||
|
Remove-Item -Path $file.FullName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function write-log {
|
||||||
|
param(
|
||||||
|
[Parameter(ValueFromPipeline = $true)]
|
||||||
|
[string]$msg,
|
||||||
|
[string]$log = $logFile
|
||||||
|
)
|
||||||
|
|
||||||
|
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss.fff"
|
||||||
|
$line = "$timestamp`t$msg"
|
||||||
|
|
||||||
|
Add-Content -Path $log -Value $line
|
||||||
|
write-host $line
|
||||||
|
}
|
||||||
|
|
||||||
|
#Get the replini-backup URI and hostname
|
||||||
|
function get-target {
|
||||||
|
$shareDS = Invoke-Sqlcmd -ServerInstance "(local)" -Database master -Query @"
|
||||||
|
SELECT SettingValue AS backupSrc, SettingId
|
||||||
|
FROM ActiveSystemServer.cfg.Settings
|
||||||
|
WHERE SettingId LIKE 'Values.Modules.Replication.DbInitializationBackupPath%'
|
||||||
|
AND LEN(SettingValue) > 1;
|
||||||
|
"@
|
||||||
|
$shareValue = $shareDS.backupSrc.Trim()
|
||||||
|
$machineName = ($shareValue -split "\\") | Where-Object { $_ -ne "" } | Select-Object -First 1
|
||||||
|
$result = [PSCustomObject]@{
|
||||||
|
smbShare = "$shareValue"
|
||||||
|
machineName = "$machineName"
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to perform SMB share reachability test
|
||||||
|
function Test-SmbShareAccessibility {
|
||||||
|
param(
|
||||||
|
[string]$sharePath,
|
||||||
|
[int]$count
|
||||||
|
)
|
||||||
|
|
||||||
|
$successfulConnections = 0
|
||||||
|
$latencyTimes = @()
|
||||||
|
write-log "to check: $sharePath"
|
||||||
|
|
||||||
|
for ($i = 1; $i -le $count; $i++) {
|
||||||
|
# Measure the time taken to check share accessibility
|
||||||
|
$startTime = [DateTime]::Now
|
||||||
|
|
||||||
|
# Check if the SMB share is accessible using Test-Path
|
||||||
|
if (Test-Path -Path $sharePath) {
|
||||||
|
$successfulConnections++
|
||||||
|
$latencyTimes += (([DateTime]::Now) - $startTime).TotalMilliseconds
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
# Log failed connection as N/A latency
|
||||||
|
$latencyTimes += "N/A"
|
||||||
|
}
|
||||||
|
|
||||||
|
Start-Sleep -Milliseconds 500 # Slight delay between attempts
|
||||||
|
}
|
||||||
|
|
||||||
|
# Calculate packet loss percentage
|
||||||
|
$packetLoss = (($count - $successfulConnections) / $count) * 100
|
||||||
|
|
||||||
|
# Calculate average latency excluding N/A entries
|
||||||
|
$avgLatency = ($latencyTimes | Where-Object { $_ -ne "N/A" } | Measure-Object -Average).Average
|
||||||
|
|
||||||
|
return [pscustomobject]@{
|
||||||
|
Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
||||||
|
SMBShare = $sharePath
|
||||||
|
PacketLoss = "$packetLoss"
|
||||||
|
AvgLatency = if ($null -ne $avgLatency) { $avgLatency } else { "N/A" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to perform TCP latency and packet loss test
|
||||||
|
function Test-TcpLatencyAndPacketLoss {
|
||||||
|
param(
|
||||||
|
[string]$target,
|
||||||
|
[int]$port,
|
||||||
|
[int]$count
|
||||||
|
)
|
||||||
|
|
||||||
|
$successfulConnections = 0
|
||||||
|
$latencyTimes = @()
|
||||||
|
|
||||||
|
for ($i = 1; $i -le $count; $i++) {
|
||||||
|
# Perform TCP connection test using Test-NetConnection
|
||||||
|
$tcpTest = Test-NetConnection -ComputerName $target -Port $port -InformationLevel Quiet
|
||||||
|
|
||||||
|
if ($tcpTest) {
|
||||||
|
$successfulConnections++
|
||||||
|
# Simulate latency as the connection time (since Test-NetConnection does not give latency directly)
|
||||||
|
$connectionStart = [DateTime]::Now
|
||||||
|
$tcpTest = Test-NetConnection -ComputerName $target -Port $port -InformationLevel Quiet
|
||||||
|
$connectionEnd = [DateTime]::Now
|
||||||
|
$latency = ($connectionEnd - $connectionStart).TotalMilliseconds
|
||||||
|
$latencyTimes += $latency
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
# Log failed connection as N/A latency
|
||||||
|
$latencyTimes += "N/A"
|
||||||
|
}
|
||||||
|
|
||||||
|
Start-Sleep -Milliseconds 500 # Slight delay between attempts
|
||||||
|
}
|
||||||
|
|
||||||
|
# Calculate packet loss percentage
|
||||||
|
$packetLoss = (($count - $successfulConnections) / $count) * 100
|
||||||
|
|
||||||
|
# Calculate average latency excluding N/A entries
|
||||||
|
$avgLatency = ($latencyTimes | Where-Object { $_ -ne "N/A" } | Measure-Object -Average).Average
|
||||||
|
|
||||||
|
return [pscustomobject]@{
|
||||||
|
Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
||||||
|
Machine = $target
|
||||||
|
Port = $port
|
||||||
|
PacketLoss = "$packetLoss"
|
||||||
|
AvgLatency = if ($null -ne $avgLatency) { $avgLatency } else { "N/A" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (-not (Test-Path $rootDrive)) {
|
||||||
|
write-log "No $rootDrive drive is present"
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$trg = get-target
|
||||||
|
$targetMachine = $trg.machineName
|
||||||
|
$targetShare = $trg.smbShare
|
||||||
|
|
||||||
|
# Run the TCP latency and packet loss test
|
||||||
|
$result = Test-TcpLatencyAndPacketLoss -target $targetMachine -port $tcpPort -count $testCount
|
||||||
|
|
||||||
|
# Check the CSV file size
|
||||||
|
$csvFileSize = Check-CsvFileSize -filePath $outputCsvLAT
|
||||||
|
|
||||||
|
# If the file size exceeds the threshold, rotate the file. Force casting of the values to [double] to ensure it's not a string comparison
|
||||||
|
if ([double]$csvFileSize -ge [double]$maxFileSizeMB) {
|
||||||
|
Rotate-CsvFile -filePath $outputCsvLAT -rotationPath $dest -maxFiles $maxFiles
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check if the CSV file exists, if not create it
|
||||||
|
if (-not (Test-Path $outputCsvLAT)) {
|
||||||
|
# Create CSV file with headers
|
||||||
|
$result | Export-Csv -Path $outputCsvLAT -NoTypeInformation
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
# Append the result to the CSV file
|
||||||
|
$result | Export-Csv -Path $outputCsvLAT -NoTypeInformation -Append
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,220 @@
|
|||||||
|
$targetMachine = "GCMPRDCENT" # Define the target SMB share and output CSV file
|
||||||
|
$tcpPort = 1433 # Specify the port number to test (e.g., HTTP = 80, HTTPS = 443)
|
||||||
|
$rootDrive = "U:\" #root drive where files will be stored
|
||||||
|
$subFolder = "TPDT-676" #subfolder where all files will be stored on the $rootDrive
|
||||||
|
|
||||||
|
#ensure we have a working drive
|
||||||
|
if(-not(Test-Path -Path $rootDrive)){
|
||||||
|
$rootDrive = "D:\"
|
||||||
|
}
|
||||||
|
|
||||||
|
#create the destination folder if missing
|
||||||
|
$dest = "$rootDrive\$subFolder".Replace("\\","\")
|
||||||
|
if (-not (Test-Path -Path $dest)) {
|
||||||
|
New-Item -ItemType Directory -Path $dest
|
||||||
|
}
|
||||||
|
|
||||||
|
$outputCsvLAT = "$dest\tpdt-676-hcimon.csv" #name of the csv file with teh results
|
||||||
|
$logFile = "$dest\tpdt-676-hcimon.log" #place of log file (for debugging sql job)
|
||||||
|
|
||||||
|
$maxFiles = 3 #how many csv file we keep after doing a rotation
|
||||||
|
$maxFileSizeMB = 10 #What is the max size of a csv file before we do a rotation in MB
|
||||||
|
$testCount = 5 # Number of connection attempts per iteration
|
||||||
|
|
||||||
|
# Function to check the size of the CSV file
|
||||||
|
function Check-CsvFileSize {
|
||||||
|
param ($filePath)
|
||||||
|
|
||||||
|
if (Test-Path $filePath) {
|
||||||
|
$fileSizeMB = (Get-Item $filePath).length / 1MB
|
||||||
|
return $fileSizeMB
|
||||||
|
} else {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to rotate files
|
||||||
|
function Rotate-CsvFile {
|
||||||
|
param ($filePath, $rotationPath, $maxFiles)
|
||||||
|
|
||||||
|
#trailing backslash needed for concatenation of the path
|
||||||
|
if (-not $rotationPath.EndsWith("\")) {
|
||||||
|
$rotationPath += "\"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create rotation directory if it doesn''t exist
|
||||||
|
if (-not (Test-Path $rotationPath)) {
|
||||||
|
New-Item -ItemType Directory -Path $rotationPath
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get the current timestamp to append to the rotated filename
|
||||||
|
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
|
||||||
|
$fileName = [System.IO.Path]::GetFileNameWithoutExtension($filePath)
|
||||||
|
$fileExtension = [System.IO.Path]::GetExtension($filePath)
|
||||||
|
|
||||||
|
# Generate new rotated filename
|
||||||
|
$rotatedFileName = "$rotationPath$fileName-$timestamp$fileExtension"
|
||||||
|
|
||||||
|
# Rotate the file
|
||||||
|
Rename-Item -Path $filePath -NewName $rotatedFileName
|
||||||
|
|
||||||
|
# Get all rotated files sorted by creation time
|
||||||
|
$rotatedFiles = Get-ChildItem -Path $rotationPath -Filter "$fileName-*$fileExtension" | Sort-Object LastWriteTime -Descending
|
||||||
|
|
||||||
|
# Keep only the most recent 3 files
|
||||||
|
$filesToDelete = $rotatedFiles | Select-Object -Skip $maxFiles
|
||||||
|
foreach ($file in $filesToDelete) {
|
||||||
|
Remove-Item -Path $file.FullName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#write to log
|
||||||
|
function write-log {
|
||||||
|
param(
|
||||||
|
[Parameter(ValueFromPipeline = $true)]
|
||||||
|
[string]$msg,
|
||||||
|
[string]$log = $logFile
|
||||||
|
)
|
||||||
|
|
||||||
|
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss.fff"
|
||||||
|
$line = "$timestamp`t$msg"
|
||||||
|
|
||||||
|
Add-Content -Path $log -Value $line
|
||||||
|
write-host $line
|
||||||
|
}
|
||||||
|
|
||||||
|
#Get the replini-backup URI and hostname from ActiveSystemServer settings
|
||||||
|
function get-target {
|
||||||
|
$shareDS = Invoke-Sqlcmd -ServerInstance "(local)" -Database master -Query @"
|
||||||
|
SELECT SettingValue AS backupSrc, SettingId
|
||||||
|
FROM ActiveSystemServer.cfg.Settings
|
||||||
|
WHERE SettingId LIKE ''Values.Modules.Replication.DbInitializationBackupPath%''
|
||||||
|
AND LEN(SettingValue) > 1;
|
||||||
|
"@
|
||||||
|
$shareValue = $shareDS.backupSrc.Trim()
|
||||||
|
$machineName = ($shareValue -split "\\") | Where-Object { $_ -ne "" } | Select-Object -First 1
|
||||||
|
$result = [PSCustomObject]@{
|
||||||
|
smbShare = "$shareValue"
|
||||||
|
machineName = "$machineName"
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to perform SMB share reachability test
|
||||||
|
function Test-SmbShareAccessibility {
|
||||||
|
param(
|
||||||
|
[string]$sharePath,
|
||||||
|
[int]$count
|
||||||
|
)
|
||||||
|
|
||||||
|
$successfulConnections = 0
|
||||||
|
$latencyTimes = @()
|
||||||
|
write-log "to check: $sharePath"
|
||||||
|
|
||||||
|
for ($i = 1; $i -le $count; $i++) {
|
||||||
|
# Measure the time taken to check share accessibility
|
||||||
|
$startTime = [DateTime]::Now
|
||||||
|
|
||||||
|
# Check if the SMB share is accessible using Test-Path
|
||||||
|
if (Test-Path -Path $sharePath) {
|
||||||
|
$successfulConnections++
|
||||||
|
$latencyTimes += (([DateTime]::Now) - $startTime).TotalMilliseconds
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
# Log failed connection as N/A latency
|
||||||
|
$latencyTimes += "N/A"
|
||||||
|
}
|
||||||
|
|
||||||
|
Start-Sleep -Milliseconds 500 # Slight delay between attempts
|
||||||
|
}
|
||||||
|
|
||||||
|
# Calculate packet loss percentage
|
||||||
|
$packetLoss = (($count - $successfulConnections) / $count) * 100
|
||||||
|
|
||||||
|
# Calculate average latency excluding N/A entries
|
||||||
|
$avgLatency = ($latencyTimes | Where-Object { $_ -ne "N/A" } | Measure-Object -Average).Average
|
||||||
|
|
||||||
|
return [pscustomobject]@{
|
||||||
|
Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
||||||
|
SMBShare = $sharePath
|
||||||
|
PacketLoss = "$packetLoss"
|
||||||
|
AvgLatency = if ($null -ne $avgLatency) { $avgLatency } else { "N/A" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to perform TCP latency and packet loss test
|
||||||
|
function Test-TcpLatencyAndPacketLoss {
|
||||||
|
param(
|
||||||
|
[string]$target,
|
||||||
|
[int]$port,
|
||||||
|
[int]$count
|
||||||
|
)
|
||||||
|
|
||||||
|
$successfulConnections = 0
|
||||||
|
$latencyTimes = @()
|
||||||
|
|
||||||
|
for ($i = 1; $i -le $count; $i++) {
|
||||||
|
# Perform TCP connection test using Test-NetConnection
|
||||||
|
$tcpTest = Test-NetConnection -ComputerName $target -Port $port -InformationLevel Quiet
|
||||||
|
|
||||||
|
if ($tcpTest) {
|
||||||
|
$successfulConnections++
|
||||||
|
# Simulate latency as the connection time (since Test-NetConnection does not give latency directly)
|
||||||
|
$connectionStart = [DateTime]::Now
|
||||||
|
$tcpTest = Test-NetConnection -ComputerName $target -Port $port -InformationLevel Quiet
|
||||||
|
$connectionEnd = [DateTime]::Now
|
||||||
|
$latency = ($connectionEnd - $connectionStart).TotalMilliseconds
|
||||||
|
$latencyTimes += $latency
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
# Log failed connection as N/A latency
|
||||||
|
$latencyTimes += "N/A"
|
||||||
|
}
|
||||||
|
|
||||||
|
Start-Sleep -Milliseconds 500 # Slight delay between attempts
|
||||||
|
}
|
||||||
|
|
||||||
|
# Calculate packet loss percentage
|
||||||
|
$packetLoss = (($count - $successfulConnections) / $count) * 100
|
||||||
|
|
||||||
|
# Calculate average latency excluding N/A entries
|
||||||
|
$avgLatency = ($latencyTimes | Where-Object { $_ -ne "N/A" } | Measure-Object -Average).Average
|
||||||
|
|
||||||
|
return [pscustomobject]@{
|
||||||
|
Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
||||||
|
Machine = $target
|
||||||
|
Port = $port
|
||||||
|
PacketLoss = "$packetLoss"
|
||||||
|
AvgLatency = if ($null -ne $avgLatency) { $avgLatency } else { "N/A" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not (Test-Path $rootDrive)) {
|
||||||
|
write-log "No $rootDrive drive is present, skipping checks."
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
# Run the TCP latency and packet loss test
|
||||||
|
$result = Test-TcpLatencyAndPacketLoss -target $targetMachine -port $tcpPort -count $testCount
|
||||||
|
|
||||||
|
# Check the CSV file size
|
||||||
|
$csvFileSize = Check-CsvFileSize -filePath $outputCsvLAT
|
||||||
|
|
||||||
|
# If the file size exceeds the threshold, rotate the file. Force casting of the values to [double] to ensure it's not a string comparison
|
||||||
|
if ([double]$csvFileSize -ge [double]$maxFileSizeMB) {
|
||||||
|
Rotate-CsvFile -filePath $outputCsvLAT -rotationPath $dest -maxFiles $maxFiles
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check if the CSV file exists, if not create it
|
||||||
|
if (-not (Test-Path $outputCsvLAT)) {
|
||||||
|
# Create CSV file with headers
|
||||||
|
$result | Export-Csv -Path $outputCsvLAT -NoTypeInformation
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
# Append the result to the CSV file
|
||||||
|
$result | Export-Csv -Path $outputCsvLAT -NoTypeInformation -Append
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,279 @@
|
|||||||
|
$tcpPort = 1433 # Specify the port number to test (e.g., HTTP = 80, HTTPS = 443)
|
||||||
|
$rootDrive = "U:\" #root drive where files will be stored
|
||||||
|
$subFolder = "TPDT-676" #subfolder where all files will be stored on the $rootDrive
|
||||||
|
|
||||||
|
#ensure we have a working drive
|
||||||
|
if(-not(Test-Path -Path $rootDrive)){
|
||||||
|
$rootDrive = "D:\"
|
||||||
|
}
|
||||||
|
|
||||||
|
#create the destination folder if missing
|
||||||
|
$dest = "$rootDrive\$subFolder".Replace("\\","\")
|
||||||
|
if (-not (Test-Path -Path $dest)) {
|
||||||
|
New-Item -ItemType Directory -Path $dest
|
||||||
|
}
|
||||||
|
|
||||||
|
$outputCsvLAT = "$dest\tpdt-676-POS.csv" #name of the csv file with teh results
|
||||||
|
$logFile = "$dest\tpdt-676-POS.log" #place of log file (for debugging sql job)
|
||||||
|
|
||||||
|
$maxFiles = 3 #how many csv file we keep after doing a rotation
|
||||||
|
$maxFileSizeMB = 10 #What is the max size of a csv file before we do a rotation in MB
|
||||||
|
$testCount = 5 # Number of connection attempts per iteration
|
||||||
|
|
||||||
|
#list of POS to check
|
||||||
|
$psList = @(
|
||||||
|
"CAMA34945659T05",
|
||||||
|
"CAMA04140508T10",
|
||||||
|
"CSUN89545123T13",
|
||||||
|
"CAMA32144422T04",
|
||||||
|
"WSU186A07",
|
||||||
|
"WAM083A04",
|
||||||
|
"CAMA00180002T07",
|
||||||
|
"CAMA26338993T08",
|
||||||
|
"CAMA25680308T12",
|
||||||
|
"CAMA10680305T05",
|
||||||
|
"WCV853A04",
|
||||||
|
"CAMA31345688T05",
|
||||||
|
"CAMA22080072T13",
|
||||||
|
"CCVI81639628T03",
|
||||||
|
"WAM060B03",
|
||||||
|
"CSUN17180460T04",
|
||||||
|
"WCV806A10",
|
||||||
|
"CAMA01740468T08",
|
||||||
|
"CCVI83342696T11",
|
||||||
|
"CCVI84339629T04",
|
||||||
|
"WAM216A06",
|
||||||
|
"CSUN14334905T03",
|
||||||
|
"WAM269A03",
|
||||||
|
"WAM080A03",
|
||||||
|
"WCV832A04",
|
||||||
|
"WCV848A08",
|
||||||
|
"CAMA28336544T05",
|
||||||
|
"CAMA60180481T10",
|
||||||
|
"WSU721A08",
|
||||||
|
"CAMA02980066T05",
|
||||||
|
"CAMA89843155T12",
|
||||||
|
"CAMA29632238T05",
|
||||||
|
"CAMA09038344T03",
|
||||||
|
"WCV836B04",
|
||||||
|
"WAM601A03",
|
||||||
|
"CAMA23334459T10",
|
||||||
|
"WAM065B05",
|
||||||
|
"WCV812B09",
|
||||||
|
"WAM626A10",
|
||||||
|
"WCV267A05",
|
||||||
|
"WSU141B09",
|
||||||
|
"WCV50705",
|
||||||
|
"CAMA24946011T04",
|
||||||
|
"CSUN12145469T05",
|
||||||
|
"CAMA08136638T10",
|
||||||
|
"CAMA51080448T04",
|
||||||
|
"WCV844A04",
|
||||||
|
"WSU841A02",
|
||||||
|
"CSUN64580053T02",
|
||||||
|
"CCVI24335530T06"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Function to check the size of the CSV file
|
||||||
|
function Check-CsvFileSize {
|
||||||
|
param ($filePath)
|
||||||
|
|
||||||
|
if (Test-Path $filePath) {
|
||||||
|
$fileSizeMB = (Get-Item $filePath).length / 1MB
|
||||||
|
return $fileSizeMB
|
||||||
|
} else {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to rotate files
|
||||||
|
function Rotate-CsvFile {
|
||||||
|
param ($filePath, $rotationPath, $maxFiles)
|
||||||
|
|
||||||
|
#trailing backslash needed for concatenation of the path
|
||||||
|
if (-not $rotationPath.EndsWith("\")) {
|
||||||
|
$rotationPath += "\"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create rotation directory if it doesn''t exist
|
||||||
|
if (-not (Test-Path $rotationPath)) {
|
||||||
|
New-Item -ItemType Directory -Path $rotationPath
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get the current timestamp to append to the rotated filename
|
||||||
|
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
|
||||||
|
$fileName = [System.IO.Path]::GetFileNameWithoutExtension($filePath)
|
||||||
|
$fileExtension = [System.IO.Path]::GetExtension($filePath)
|
||||||
|
|
||||||
|
# Generate new rotated filename
|
||||||
|
$rotatedFileName = "$rotationPath$fileName-$timestamp$fileExtension"
|
||||||
|
|
||||||
|
# Rotate the file
|
||||||
|
Rename-Item -Path $filePath -NewName $rotatedFileName
|
||||||
|
|
||||||
|
# Get all rotated files sorted by creation time
|
||||||
|
$rotatedFiles = Get-ChildItem -Path $rotationPath -Filter "$fileName-*$fileExtension" | Sort-Object LastWriteTime -Descending
|
||||||
|
|
||||||
|
# Keep only the most recent 3 files
|
||||||
|
$filesToDelete = $rotatedFiles | Select-Object -Skip $maxFiles
|
||||||
|
foreach ($file in $filesToDelete) {
|
||||||
|
Remove-Item -Path $file.FullName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#write to log
|
||||||
|
function write-log {
|
||||||
|
param(
|
||||||
|
[Parameter(ValueFromPipeline = $true)]
|
||||||
|
[string]$msg,
|
||||||
|
[string]$log = $logFile
|
||||||
|
)
|
||||||
|
|
||||||
|
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss.fff"
|
||||||
|
$line = "$timestamp`t$msg"
|
||||||
|
|
||||||
|
Add-Content -Path $log -Value $line
|
||||||
|
write-host $line
|
||||||
|
}
|
||||||
|
|
||||||
|
#Get the replini-backup URI and hostname from ActiveSystemServer settings
|
||||||
|
function get-target {
|
||||||
|
$shareDS = Invoke-Sqlcmd -ServerInstance "(local)" -Database master -Query @"
|
||||||
|
SELECT SettingValue AS backupSrc, SettingId
|
||||||
|
FROM ActiveSystemServer.cfg.Settings
|
||||||
|
WHERE SettingId LIKE ''Values.Modules.Replication.DbInitializationBackupPath%''
|
||||||
|
AND LEN(SettingValue) > 1;
|
||||||
|
"@
|
||||||
|
$shareValue = $shareDS.backupSrc.Trim()
|
||||||
|
$machineName = ($shareValue -split "\\") | Where-Object { $_ -ne "" } | Select-Object -First 1
|
||||||
|
$result = [PSCustomObject]@{
|
||||||
|
smbShare = "$shareValue"
|
||||||
|
machineName = "$machineName"
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to perform SMB share reachability test
|
||||||
|
function Test-SmbShareAccessibility {
|
||||||
|
param(
|
||||||
|
[string]$sharePath,
|
||||||
|
[int]$count
|
||||||
|
)
|
||||||
|
|
||||||
|
$successfulConnections = 0
|
||||||
|
$latencyTimes = @()
|
||||||
|
write-log "to check: $sharePath"
|
||||||
|
|
||||||
|
for ($i = 1; $i -le $count; $i++) {
|
||||||
|
# Measure the time taken to check share accessibility
|
||||||
|
$startTime = [DateTime]::Now
|
||||||
|
|
||||||
|
# Check if the SMB share is accessible using Test-Path
|
||||||
|
if (Test-Path -Path $sharePath) {
|
||||||
|
$successfulConnections++
|
||||||
|
$latencyTimes += (([DateTime]::Now) - $startTime).TotalMilliseconds
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
# Log failed connection as N/A latency
|
||||||
|
$latencyTimes += "N/A"
|
||||||
|
}
|
||||||
|
|
||||||
|
Start-Sleep -Milliseconds 500 # Slight delay between attempts
|
||||||
|
}
|
||||||
|
|
||||||
|
# Calculate packet loss percentage
|
||||||
|
$packetLoss = (($count - $successfulConnections) / $count) * 100
|
||||||
|
|
||||||
|
# Calculate average latency excluding N/A entries
|
||||||
|
$avgLatency = ($latencyTimes | Where-Object { $_ -ne "N/A" } | Measure-Object -Average).Average
|
||||||
|
|
||||||
|
return [pscustomobject]@{
|
||||||
|
Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
||||||
|
SMBShare = $sharePath
|
||||||
|
PacketLoss = "$packetLoss"
|
||||||
|
AvgLatency = if ($null -ne $avgLatency) { $avgLatency } else { "N/A" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to perform TCP latency and packet loss test
|
||||||
|
function Test-TcpLatencyAndPacketLoss {
|
||||||
|
param(
|
||||||
|
[string]$target,
|
||||||
|
[int]$port,
|
||||||
|
[int]$count
|
||||||
|
)
|
||||||
|
|
||||||
|
$successfulConnections = 0
|
||||||
|
$latencyTimes = @()
|
||||||
|
|
||||||
|
for ($i = 1; $i -le $count; $i++) {
|
||||||
|
# Perform TCP connection test using Test-NetConnection
|
||||||
|
$tcpTest = Test-NetConnection -ComputerName $target -Port $port -InformationLevel Quiet
|
||||||
|
|
||||||
|
if ($tcpTest) {
|
||||||
|
$successfulConnections++
|
||||||
|
# Simulate latency as the connection time (since Test-NetConnection does not give latency directly)
|
||||||
|
$connectionStart = [DateTime]::Now
|
||||||
|
$tcpTest = Test-NetConnection -ComputerName $target -Port $port -InformationLevel Quiet
|
||||||
|
$connectionEnd = [DateTime]::Now
|
||||||
|
$latency = ($connectionEnd - $connectionStart).TotalMilliseconds
|
||||||
|
$latencyTimes += $latency
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
# Log failed connection as N/A latency
|
||||||
|
$latencyTimes += "N/A"
|
||||||
|
}
|
||||||
|
|
||||||
|
Start-Sleep -Milliseconds 500 # Slight delay between attempts
|
||||||
|
}
|
||||||
|
|
||||||
|
# Calculate packet loss percentage
|
||||||
|
$packetLoss = (($count - $successfulConnections) / $count) * 100
|
||||||
|
|
||||||
|
# Calculate average latency excluding N/A entries
|
||||||
|
$avgLatency = ($latencyTimes | Where-Object { $_ -ne "N/A" } | Measure-Object -Average).Average
|
||||||
|
|
||||||
|
return [pscustomobject]@{
|
||||||
|
Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
||||||
|
Machine = $target
|
||||||
|
Port = $port
|
||||||
|
PacketLoss = "$packetLoss"
|
||||||
|
AvgLatency = if ($null -ne $avgLatency) { $avgLatency } else { "N/A" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not (Test-Path $rootDrive)) {
|
||||||
|
write-log "No $rootDrive drive is present, skipping checks."
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
$psList | ForEach-Object {
|
||||||
|
$pos_name = $_
|
||||||
|
Write-Output "pos name: $pos_name"
|
||||||
|
|
||||||
|
# Run the TCP latency and packet loss test
|
||||||
|
$result = Test-TcpLatencyAndPacketLoss -target $pos_name -port $tcpPort -count $testCount
|
||||||
|
|
||||||
|
# Check the CSV file size
|
||||||
|
$csvFileSize = Check-CsvFileSize -filePath $outputCsvLAT
|
||||||
|
|
||||||
|
# If the file size exceeds the threshold, rotate the file. Force casting of the values to [double] to ensure it's not a string comparison
|
||||||
|
if ([double]$csvFileSize -ge [double]$maxFileSizeMB) {
|
||||||
|
Rotate-CsvFile -filePath $outputCsvLAT -rotationPath $dest -maxFiles $maxFiles
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check if the CSV file exists, if not create it
|
||||||
|
if (-not (Test-Path $outputCsvLAT)) {
|
||||||
|
# Create CSV file with headers
|
||||||
|
$result | Export-Csv -Path $outputCsvLAT -NoTypeInformation
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
# Append the result to the CSV file
|
||||||
|
$result | Export-Csv -Path $outputCsvLAT -NoTypeInformation -Append
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
60
sql filters arizona db.sql
Normal file
60
sql filters arizona db.sql
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
Server: samnb705db01.amavita.ch
|
||||||
|
Format: GCM
|
||||||
|
Business: TPPHAR
|
||||||
|
type: VALI
|
||||||
|
Version: 23.1.21006.00066
|
||||||
|
|
||||||
|
24.06.2024, TSC
|
||||||
|
*/
|
||||||
|
use Arizona_delphix
|
||||||
|
|
||||||
|
select Organizational_unit_ID, OU_subsidiary, OU_system_site, OU_profit_cost_center, OU_address, OU_code, OU_short_name, OU_type, OU_database_name, OU_TS, OU_email, OU_VGUID, OU_master_ID, OU_manager_address, OU_item_dispatch_type, OU_rowguid, OU_pharmacy_code
|
||||||
|
from Organizational_unit
|
||||||
|
where not exists(select 1 from dbo.address where address.tt_masking='persist' and address.Address_ID=OU_address)
|
||||||
|
or not exists(select 1 from dbo.address where address.tt_masking='persist' and address.Address_ID=OU_manager_address)
|
||||||
|
|
||||||
|
select PH_insurance_GUID, PHIN_address, PHIN_key, PHIN_EAN_key, PHIN_type, PHIN_invoice_type, PHIN_name_french, PHIN_name_german, PHIN_name_italian, PHIN_slogan_french, PHIN_slogan_german, PHIN_slogan_italian, PHIN_type_of_proof, PHIN_plan_LS, PHIN_plan_HL, PHIN_plan_MC, PHIN_plan_LPPA, PHIN_plan_FHLN, PHIN_check_physician_number, PHIN_address_1, PHIN_address_2, PHIN_zip_code, PHIN_location, PHIN_language, PHIN_telephone, PHIN_fax, PHIN_IN_minimum_length, PHIN_IN_maximum_length, PHIN_IN_type, PHIN_IN_alignment, PHIN_IN_start_position, PHIN_IN_end_position, PHIN_IN_check_digit_ref, PHIN_ISO_key, PHIN_section_minimum_length, PHIN_section_maximum_length, PHIN_section_type, PHIN_section_alignment, PHIN_invoicing_method, PHIN_origin, PHIN_invoice_transmission, PHIN_APS_TS, PHIN_TS, PHIN_VGUID, PHIN_master_ID, PHIN_bill_to, PHIN_status, PHIN_renewable_bonus_factor, PHIN_insurance_bonus_factor, PHIN_recipient_EAN_key, PHIN_Invoice_delay, PHIN_Invoice_gap, PHIN_view_prescription_image, PHIN_hl_accept_limited_coverage, PHIN_mc_accept_limited_coverage, PHIN_code_model, PHIN_benefit_number, PHIN_tp_min_amount, PHIN_tp_min_amount_invoice, PHIN_assignment_of_claim, PHIN_rowguid, PHIN_pharmacy_code, PHIN_contract_name
|
||||||
|
from PH_insurance
|
||||||
|
where not exists(select 1 from dbo.address where address.tt_masking='persist' and address.Address_ID=PHIN_address)
|
||||||
|
|
||||||
|
select PH_organizational_unit_GUID, PHOU_organizational_unit, PHOU_manager_address, PHOU_galenica_ID, PHOU_ofac_ID, PHOU_EAN_number, PHOU_contract_number, PHOU_ofac_invoice_limit, PHOU_manager_data_to_print, PHOU_TS, PHOU_APS_TS, PHOU_VGUID, PHOU_master_ID, PHOU_ofac_invoice_alert, PHOU_ofac_max_documents, PHOU_posology_label_header, PHOU_IMS_ID, PHOU_sales_insurance_check, PHOU_loyalty_ID, PHOU_NIF, PHOU_IMS_ID_DP, PHOU_distribution_center, PHOU_AB_level, PHOU_AB_schedule_day_of_month, PHOU_AB_schedule_month, PHOU_AB_schedule_day_of_week, PHOU_AB_closing_mode, PHOU_AB_delivery_delay, PHOU_rowguid, PHOU_pharmacy_code, PHOU_EPD_provider, PHOU_OID, PHOU_mediproc_nursing_home
|
||||||
|
from PH_Organizational_unit
|
||||||
|
where not exists(select 1 from dbo.address where address.tt_masking='persist' and address.Address_ID=PHOU_manager_address)
|
||||||
|
or not exists(select 1 from dbo.address where address.tt_masking='persist' and address.Address_ID=PHOU_distribution_center)
|
||||||
|
|
||||||
|
select PH_prescriber_GUID, PHPR_address, PHPR_contract_number, PHPR_EAN_number, PHPR_remark, PHPR_origin, PHPR_APS_TS, PHPR_TS, PHPR_VGUID, PHPR_master_ID, PHPR_status, PHPR_store_remark, PHPR_spa_sequence, PHPR_deactivation_date, PHPR_tiers_garant_only, PHPR_contract_number_state
|
||||||
|
from PH_prescriber
|
||||||
|
where not exists(select 1 from dbo.address where address.tt_masking='persist' and address.Address_ID=PHPR_address)
|
||||||
|
|
||||||
|
select Incident_header_ID, INH_subsidiary, INH_received_by, INH_originator_address, INH_default_incident_type, INH_incident_number, INH_caller_name, INH_call_date, INH_TS, INH_VGUID, INH_master_ID, INH_contact_address, INH_caller_number
|
||||||
|
from Incident_header
|
||||||
|
where not exists(select 1 from dbo.address where address.tt_masking='persist' and address.Address_ID=INH_contact_address)
|
||||||
|
or not exists(select 1 from dbo.address where address.tt_masking='persist' and address.Address_ID=INH_originator_address)
|
||||||
|
|
||||||
|
select Serial_number_history_ID, SNH_serial_number, SNH_serial_number_status, SNH_address, SNH_document_line, SNH_value_date, SNH_remark, SNH_APS_TS, SNH_TS, SNH_VGUID, SNH_master_ID
|
||||||
|
from Serial_number_history
|
||||||
|
where not exists(select 1 from dbo.address where address.tt_masking='persist' and address.Address_ID=SNH_address)
|
||||||
|
|
||||||
|
select Item_relation_info_ID, ITRI_item, ITRI_address, ITRI_address_type, ITRI_BOM_option_header, ITRI_process_option, ITRI_address_item_number, ITRI_text, ITRI_barcode, ITRI_legalized, ITRI_quality_control_remark, ITRI_ALT_weighting_factor, ITRI_certification, ITRI_remark, ITRI_APS_TS, ITRI_VGUID, ITRI_master_ID, ITRI_TS, ITRI_ALT_weighting_factor_unit, ITRI_delivery_delay, ITRI_order_weeks, ITRI_availability_status, ITRI_availability_value_date, ITRI_availability_origin, ITRI_availability_refresh_date, ITRI_availability_remark, ITRI_default_pharmacy_priority, ITRI_pharmacy_availability, ITRI_origin, ITRI_default_central_priority, ITRI_stock_info_code
|
||||||
|
from Item_relation_info
|
||||||
|
where not exists(select 1 from dbo.address where address.tt_masking='persist' and address.Address_ID=ITRI_address)
|
||||||
|
|
||||||
|
select Fixed_price_ID, FP_subsidiary, FP_tariff_type, FP_item_price_range, FP_item, FP_address_group, FP_address_category, FP_address, FP_currency, FP_price_code, FP_sales_tax_code, FP_SP_catalog, FP_start_date, FP_end_date, FP_tax_free_price_per_unit, FP_tax_free_min_price_per_unit, FP_tax_free_max_price_per_unit, FP_tax_incl_price_per_unit, FP_tax_incl_min_price_per_unit, FP_tax_incl_max_price_per_unit, FP_price_per_unit_factor, FP_price_per_unit_unit_code, FP_tax_free_flat_fee, FP_tax_incl_flat_fee, FP_flat_fee_quantity, FP_quantity, FP_unit_code, FP_final_discount_possible, FP_bonus_order_quantity, FP_bonus_delivery_quantity, FP_label_type, FP_discount_level_1_possible, FP_discount_level_2_possible, FP_origin, FP_manual_price, FP_remark, FP_APS_TS, FP_VGUID, FP_master_ID, FP_TS, FP_bonus_order_point_qty
|
||||||
|
from Fixed_price
|
||||||
|
where not exists(select 1 from dbo.address where address.tt_masking='persist' and address.Address_ID=FP_address)
|
||||||
|
|
||||||
|
select Tariff_ID, TF_subsidiary, TF_tariff_type, TF_item_price_range, TF_item, TF_address_group, TF_address_category, TF_address, TF_delivery_code, TF_payment_method, TF_SP_catalog, TF_marketing_activity_header, TF_assortment, TF_product_line, TF_quantity, TF_unit_code, TF_total_amount, TF_currency, TF_start_date, TF_end_date, TF_price_code, TF_discount_percentage_1, TF_discount_percentage_2, TF_margin_amount, TF_margin_factor, TF_rounding_precision, TF_price_type, TF_level, TF_final_discount_possible, TF_origin, TF_manual_tariff, TF_remark, TF_VGUID, TF_master_ID, TF_TS
|
||||||
|
from Tariff
|
||||||
|
where not exists(select 1 from dbo.address where address.tt_masking='persist' and address.Address_ID=TF_address)
|
||||||
|
|
||||||
|
select Asset_ID, AS_subsidiary, AS_depreciation_method, AS_asset_group, AS_asset_family, AS_asset_location, AS_supplier, AS_manufacturer, AS_owner, AS_entry, AS_number, AS_description, AS_remark, AS_serial_number, AS_short_description, AS_purchase_date, AS_purchase_amount, AS_implementation_date, AS_technical_life_time, AS_warranty_expiration_date, AS_supplier_reference, AS_inventory_number, AS_status, AS_number_of_ident_entities, AS_GL_initial_amount, AS_GL_assets_account, AS_assets_account, AS_GL_cost_account, AS_cost_account, AS_GL_deprec_type, AS_GL_deprec_SP, AS_GL_deprec_percentage, AS_GL_deprec_start_date, AS_GL_deprec_number_of_months, AS_GL_residual_amount_method, AS_GL_residual_percentage, AS_GL_residual_amount, AS_GL_deprec_end_date, AS_GL_deprec_account, AS_deprec_account, AS_GL_sinking_fund, AS_sinking_fund_account, AS_GL_quantity, AS_GL_quantity_unit_code, AS_GL_price_per_unit, AS_GL_price_factor, AS_GL_price_unit_code, AS_CA_initial_amount, AS_CA_deprec_type, AS_CA_deprec_SP, AS_CA_deprec_percentage, AS_CA_deprec_number_of_months, AS_CA_residual_amount_method, AS_CA_residual_percentage, AS_CA_residual_amount, AS_CA_deprec_start_date, AS_CA_deprec_end_date, AS_CA_cost_center, AS_cost_center, AS_CA_deprec_cost_center, AS_deprec_cost_center, AS_CA_deprec_cost_unit, AS_deprec_cost_type, AS_CA_sinking_fund_cost_unit, AS_sinking_fund_cost_type, AS_CA_investment_cost_unit, AS_investment_cost_type, AS_CA_quantity, AS_CA_quantity_unit_code, AS_CA_price_per_unit, AS_CA_price_factor, AS_CA_price_unit_code, AS_APS_TS, AS_VGUID, AS_master_ID, AS_TS, AS_GL_residual_balance_amount, AS_GL_residual_balance_percent, AS_CA_residual_balance_amount, AS_CA_residual_balance_percent
|
||||||
|
from Asset
|
||||||
|
where not exists(select 1 from dbo.address where address.tt_masking='persist' and address.Address_ID=AS_owner)
|
||||||
|
or not exists(select 1 from dbo.address where address.tt_masking='persist' and address.Address_ID=AS_supplier)
|
||||||
|
or not exists(select 1 from dbo.address where address.tt_masking='persist' and address.Address_ID=AS_manufacturer)
|
||||||
|
|
||||||
|
select Supplier_ID, SUPP_subsidiary, SUPP_address, SUPP_address_group, SUPP_address_category, SUPP_delivery_code, SUPP_shipping_method, SUPP_payment_terms, SUPP_payment_method, SUPP_sales_tax_code, SUPP_currency, SUPP_pay_to, SUPP_send_order_to, SUPP_default_invoicing_method, SUPP_customer_number, SUPP_order_notes_copies, SUPP_active, SUPP_active_remark, SUPP_remark, SUPP_tax_in_price, SUPP_payment_freezed, SUPP_print_payment_notice, SUPP_default_delivery_type, SUPP_bmc_user_profile, SUPP_creation_date, SUPP_VAT_method, SUPP_abc_code, SUPP_computed_abc_code, SUPP_delivery_note_sort_order, SUPP_VGUID, SUPP_master_ID, SUPP_TS, SUPP_ALT_weighting_factor, SUPP_default_backlog_type, SUPP_ALT_weighting_factor_unit, SUPP_element_requirement_term, SUPP_delivery_delay, SUPP_order_weeks, SUPP_backlog_processing_mode, SUPP_backlog_processing_delay, SUPP_external_number, SUPP_GLN_key, SUPP_COMP_key, SUPP_WHS_key
|
||||||
|
from Supplier
|
||||||
|
where not exists(select 1 from dbo.address where address.tt_masking='persist' and address.Address_ID=SUPP_pay_to)
|
||||||
|
or not exists(select 1 from dbo.address where address.tt_masking='persist' and address.Address_ID=SUPP_send_order_to)
|
||||||
Reference in New Issue
Block a user