Test if Wireless Adapter is Working Before Resetting - networking

Is there a simple way to prove if a network adapter is working? Perhaps some IP like localhost (127.0.0.1) which is always available regardless of which network I'm connected to; only one that only shows if my wireless network adapter's working? Or perhaps there's some simple diagnostic check to confirm this?
I've tagged this question as PowerShell as that's my preferred language; but I can figure out ways to integrate with any other solutions which may be suggested.
Tried so far
I thought of checking the adapter's properties and found there is a status and an IP; I figured that if there were an assigned IP or a connected status that would prove that all's working; sadly those properties are blank and unknown, so I can't use them.
$adapter = Get-WmiObject -Class Win32_NetworkAdapter | Where-Object {$_.Name -like '*Wireless*'}
$adapter.Status #returns 2; i.e. unknown
$adapter.NetworkAddresses #is blank
Background
I have an issue where I hibernate my laptop whilst docked then bring it back online no longer docked it loses its wireless connection and requires that the adapter be restarted. The same issue is mentioned in this post: Command/Powershell script to reset a network adapter
I'm hoping to use the above code to automatically resolve the issue by scheduling a task to run when my computer comes out of suspension (e.g. https://superuser.com/a/149924/156700).
Sometimes I'll be on my home network, where the only device to ping is my router, sometimes I'll be on my office network where there's a range of machines I could ping, and sometimes I'll be elsewhere... so determining a good target candidate to test whether my network adapter needs a restart by pinging some external device is more complex than ideal.
I want to run a test before resetting so that I only reset when required. It will also be useful to check once a reset has completed should I wish to queue other tasks which require network presence to complete.

It seems the WMI class Win32_NetworkAdapter has an Availability property.
https://msdn.microsoft.com/en-us/library/aa394216(v=vs.85).aspx
There are a range of values which could represent "working"; for now I've gone with only status 3; i.e. where everything's working 100% as expected / there's no concerns about potential degredation. That may be something worth amending depending on scenario.
function Test-NetworkAdapter {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]$AdapterNameMask
,
[Parameter(Mandatory = $false)]
[int[]]$HealthyStatusses = #(3) #100% working on full power; for list of other possible values, see https://msdn.microsoft.com/en-us/library/aa387884(v=vs.85).aspx
)
process {
Get-WmiObject -Class Win32_NetworkAdapter `
| Where-Object {$_.Name -like $AdapterNameMask} `
| Select-Object #{Name='Working';Expression={$healthyStatusses -contains $_.Availability}}
}
}
function Reset-NetworkAdapter {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]$AdapterNameMask
)
process {
Get-WmiObject -Class Win32_NetworkAdapter `
| Where-Object {$_.Name -like $AdapterNameMask} `
| %{ #in case multiple matches, loop through all
$_.Disable()
$_.Enable()
}
}
}
[string]$wirelessAdapterMask = '*Wireless*'
#I could probably improve this to cope better should there be multiple matches / only resetting those with issues... but for now this meets my requirement
if (-not (Test-NetworkAdapter $wirelessAdapterMask)) {
Reset-NetworkAdapter $wirelessAdapterMask
}

Related

How can I to transmit at least a "couple of bytes" on the local network (UEFI DXE)

I need to write driver (DXE), that can transmit "couple of bytes" from virtual machine (QEMU) to the host system (OS - Ubuntu). I've read the UEFI_Spec and Guide for developers, but I still don't understand, how to write the code and what protocol should I use (tried to use TCPv4 but can't even LocateHandleBuffer).
EFI_STATUS Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiTcp4ProtocolGuid, NULL, &HandleCount, &HandleBuffer);
I get:
EFI_UNSUPPORTED
If somebody can explain me or can show examples of the code, I'll be very grateful. Thanks.
For most network related protocols you first have to use the corresponding "Service Binding Protocol" to get a handle which contains the protocol you are looking for.
Use this steps to access the Tcp4Protocol:
gBS->LocateHandleBuffer(ByProtovol,gEfiTcp4ServiceBindingProtocolGuid, NULL, &HandleCount, &HandleBuffer);
// Loop over the HandleBuffer Array and pick the one you need
gBS->HandleProtocol(HandleBuffer[YourIndex], &gEfiTcp4ServiceBindingProtocolGuid, &Tcp4SBProtocol);
Tcp4SBProtocol->CreateChild(Tcp4SBProtocol, &Tcp4Handle);
gBS->HandleProtocol(Tcp4Handle, &gEfiTcp4ProtocolGuid, &Tcp4Protocol);
To check if a NIC is available you can use:
// This should return EFI_SUCCESS
gBS->LocateProtocol(&gEfiSimpleNetworkProtocolGuid, NULL, &SimpleNetworkProtocol);
There is a complete code sample for the HttpProtocol inside the Uefi specification (starting at page 1548), the Tcp4Protocol is not very different.

Zabbix - wildcard usage in perf_counter

colleges!
I really need to use wildcard in perf_counter.
We have .NET Data Provider for SqlServer counters. Unfortunately, the ID on counter changes after each reboot.
Right now I have counter like this:
perf_counter["\.NET Data Provider for SqlServer(_lm_w3svc_3_root-3-131958133162924330[18196])\NumberOfActiveConnectionPools"]
How can I use it permanently. Maybe I need to use a wildcard like this:
perf_counter["\.NET Data Provider for SqlServer(_lm_w3svc_3_root-3-131958133162924330[*])\NumberOfActiveConnectionPools"]
The counter became unsupported with "Cannot obtain performance information from collector".
I really need your help!
Thank you and have a nice day!
The documentation doesn't mention wildcards with performance counters.
If your counter changes at every reboot you need to use a discovery rule even if you're dealing with a single item.
The discovery rule could be a powershell script like:
$result = #{}
$result.data = #()
(get-counter -Listset *).paths | ForEach-Object {
if ($_ -Like "*_lm_w3svc_3_root-3-131958133162924330*\NumberOfActiveConnectionPools") {
$result.data += #{
"{#PATH}" = $_
}
}
}
$result | ConvertTo-Json
Set it to run every hour or less and create an item prototype like perf_counter["{#PATH}"], this should do the trick.

How to check which SQL query is so CPU intensive

Is there any possible way to check which query is so CPU intensive in _sqlsrv2 process?
Something which give me information about executed query in that process in that moment.
Is there any way to terminate that query without killing _sqlsrv2 process?
I cannot find any official materials in that subject.
Thank You for any help.
You could look into client database-request caching.
Code examples below assume you have ABL access to the environment. If not you will have to use SQL instead but it shouldn't be to hard to "translate" the code below
I haven't used this a lot myself but I wouldn't be surprised if it has some impact on performance.
You need to start caching in the active connection. This can be done in the connection itself or remotely via VST tables (as long as your remote session is connected to the same database) so you need to be able to identify your connections. This can be done via the process ID.
Generally how to enable the caching:
/* "_myconnection" is your current connection. You shouldn't do this */
FIND _myconnection NO-LOCK.
FIND _connect WHERE _connect-usr = _myconnection._MyConn-userid.
/* Start caching */
_connect._Connect-CachingType = 3.
DISPLAY _connect WITH FRAME x1 SIDE-LABELS WIDTH 100 1 COLUMN.
/* End caching */
_connect._Connect-CachingType = 0.
You need to identify your process first, via top or another program.
Then you can do something like:
/* Assuming pid 21966 */
FIND FIRST _connect NO-LOCK WHERE _Connect._Connect-Pid = 21966 NO-ERROR.
IF AVAILABLE _Connect THEN
DISPLAY _connect.
You could also look at the _Connect-Type. It should be 'SQLC' for SQL connections.
FOR EACH _Connect NO-LOCK WHERE _Connect._connect-type = "SQLC":
DISPLAY _connect._connect-type.
END.
Best of all would be to do this in a separate environment. If you can't at least try it in a test environment first.
Here's a good guide.
You can use a Select like this:
select
c."_Connect-type",
c."_Connect-PID" as 'PID',
c."_connect-ipaddress" as 'IP',
c."_Connect-CacheInfo"
from
pub."_connect" c
where
c."_Connect-CacheInfo" is not null
But first you need to enable connection cache, follow this example

Serial port access in vxworks not working

I am in a need to send data thru serial port in vxworks. I am using the following code. But
it is not working.can anyone point out what went wrong?
int f;
if(f=open("/tyCo/1",O_RDWR,0)<0)
{
printf("Error opening serial port.");
return 1;
}
write(f,"hello",5);
after running this code, no data is comming thru serial port but instead it comes thru
terminal(Tornado shell). The system has two serial devices /tyCo/1 and /tyCo/0. I tried them both, but the problem persists.
Thanks in adavnce
Likhin.
Have you set the baud rate?
if (iocl(m_fd, FIOBAUDRATE, rate )) == ERROR )
{
//throw error
}
It is possible that you are using the wrong name for the device, and that Tornado Shell is set to your default device. From vxdev.com:
If a matching device name cannot be found, then the I/O function is directed
at a default device. You can set this default device to be any device in the
system, including no device at all, in which case failure to match a device
name returns an error. You can obtain the current default path by using
ioDefPathGet( ). You can set the default path by using ioDefPathSet( ).
The 3rd parameter of "open" command is, if I am not wrong, the mode. I do not really understand what it is needed for in vxworks, except for code comparability with UNIX. In short -try to give some value like 0644 or 0666. I think this will help.

Deal with download interruptions in Tcl

I'm downloading a list of files using tcl's http package and was wondering what the best way to handle interruptions are. Right now the outline to my download procedure looks like this:
proc downloadFiles {url_list folder_location} {
foreach {i} $url_list {
regsub {.*/(.*)$} $i {\1} $name
set out [open $folder_location/$name w+] //not worried about errors here
if {[catch {set token [http::geturl $i -channel $out]}]} {
puts "Could not download $i"
} else {
http::cleanup $token
puts "Downloaded $i"
}
close $out
}
}
The line I'm having problems is the catch statement:
catch {set token [http::geturl $i -channel $out]}
Apparently despite me cutting off my internet and stopping a download half way the catch statement still returns a 0 for errors. Is there someway to catch this?
Detecting that the network has temporarily vanished is difficult (deliberately so; that's how TCP/IP works and HTTP just sits on top of that). What you could do is try getting the expected length of the data from the HTTP headers and comparing that to the length of data actually received (you'll want to force binary mode for this, but you're probably dealing with binary data anyway).
To get the expected data length and currently-downloaded length, you need a bit of magic with upvar (the internal alias name, state, is arbitrary):
upvar #0 $token state
puts "Content-Length was $state(totalsize), downloaded $state(currentsize)"
Note however that many pages don't supply a content length so the totalsize field is zero. The http package only knows in those cases that it's got the end when it gets to the end.
When restarting a download, you'll want to send a Range header. That's not an explicitly supported one so you'll need to give it by the -headers option to geturl.
http::geturl $url -headers [list Range bytes=$whereYouGotTo-]
Yes, the format is indeed that funky.

Resources