refresh_available_updates runs the Windows Update Agent's search against the
configured source and keeps its reading under HKLM\SOFTWARE\napalm-windows;
get_available_updates reads it back without a search, leaving out what the
history shows installed since, and raises PackageIndexMissing before the
first search. Each update carries its title, KB articles, CveIDs and
MsrcSeverity, and is named by its title without month, KB and version, so
next month's cumulative update keeps the name. Previews, feature upgrades and
drivers are left out.
apply_updates installs in a one-shot task running as SYSTEM, since Windows
refuses downloads and installs to a network logon. The task's script and the
exact UpdateID:revision chosen travel in the run's registry key; it searches
again, refuses what no longer matches exactly, what asks for input or has
unaccepted licence terms, installs nothing while a restart is pending and
never restarts. Its log is followed line by line; the next run sweeps what a
dead run left. get_scheduled_jobs shows these tasks as an application's.
get_update_history reads QueryHistory, one transaction per entry, with the
ClientApplicationID as requested_by.
get_login_accounts reads the host's own accounts (Get-LocalUser), their
last login and failed attempts from the account database, expiry and
lock, and whether each is an administrator (S-1-5-32-544, by SID) or may
log in over Remote Desktop (the logon right and its denial from
secedit, the host's fDenyTSConnections). groups lists the groups that
grant either, with every member, a domain's included. uid is the RID,
sid the SID. A domain controller's accounts are not read.
get_login_sessions reads logon events 4624 of type 2, 10 and 11 of the
last seven days from the Security log, ended by 4634/4647, an
administrator's two linked logons as one session. own_address is the
reading's own WinRM logon's address; records_since the log's oldest
event. A log without any logon raises LoginSessionsUnavailable.
Both scripts are in tools/harvest.py.
WindowsLogSourcesMixin.get_log_sources lists every event channel that is
switched on and holds records (Get-WinEvent -ListLog *) as a source of kind
eventlog, named by its channel, with its .evtx file, size and last write.
Analytic and debug channels are left out. README and CHANGELOG describe the
services, host events and log sources readings.
WindowsHostEventsMixin.get_host_events(since=None) reads, in one script, three
bounded queries over the window: the System log's rare events (Kernel-Power 41,
EventLog 6008, WER-SystemErrorReporting 1001, WHEA-Logger 18, disk 7, Ntfs 55)
with their messages, its frequent ones (WHEA-Logger 19/47, disk 153, Service
Control Manager 7031/7034) and the Application log's crashes (Application Error
1000). Each query catches NoMatchingEventsFound; one that fails names its kinds
unread, one read up to its bound names them capped.
get_host_firewall reads the Windows Firewall: the profiles' settings in
force, every enabled rule of the active policy with its filters read in
bulk and joined on InstanceID, and the profile of each connected
interface. get_windows_features lists the image's optional features
with their state from Win32_OptionalFeature. Both scripts are in the
harvest.
WindowsStorageMixin implements napalm-device-types' HostStorageMixin, so
the host reports its storage and stays a host:
- get_disks: Get-PhysicalDisk with medium, bus, Windows' health and the
Storage Spaces pool a disk is in; a Storage Spaces virtual disk is no
physical disk.
- get_disk_smart: Get-StorageReliabilityCounter per disk (temperature,
wear, power-on hours, uncorrected read and write errors). A counter
that cannot be read is no counter, not an error; disks that report
nothing are left out.
- get_disk_pools: Storage Spaces' pools.
- get_volumes: fixed volumes mounted at a drive letter or in a folder,
with file system and health.
A disk whose medium Windows cannot tell and whose counters are empty (a
virtual disk, a RAID controller's logical disk) reads temperature -1 and
health "unknown". Every script probes its cmdlets first. The fixtures
are synthetic; the scripts are in harvest.py for the first real host.
get_services moves into WindowsServicesMixin and reads, beside state and start
mode, Win32_Service's ExitCode (1066 hands over to ServiceSpecificExitCode, 1077
is not started since boot), StartName and whether a TriggerInfo key starts the
service, as napalm-device-types' ServiceDict result, exit_code, trigger_start
and account.
verify_system_files (sfc /verifyonly), check_component_store (DISM
/ScanHealth /English), update_antimalware_signatures (Update-MpSignature)
and scan_antimalware (Start-MpScan, quick or full), each one bounded PSRP
call streamed line by line through PsrpTransport.run_streaming. Native
tools run as a process read in their own encoding (sfc: UTF-16), and NULs
of UTF-16 read byte by byte are dropped. The exit code decides; a missing
tool or Defender says it is not available. sfc /scannow and DISM
/RestoreHealth stay undefined until a real host was tested.
tools/harvest.py --runs records the runs' output.
get_hardening() reads Secure Boot, the TPM, BitLocker per volume, Defender,
the firewall profiles' state and virtualization-based security in one script,
each part caught on its own and each cmdlet probed with Get-Command first.
BitLocker through Win32_EncryptableVolume, never Get-BitLockerVolume: no
recovery password or key protector is read.
reboot_host() and shutdown_host() run Restart-Computer and Stop-Computer
without -Force over the PSRP connection: Windows asks running programs
to close and refuses while other users are logged on. A refusal raises
RuntimeError with the host's answer; a connection the host drops before
answering counts as accepted, which PsrpTransport.run_last() reports.
netOrk keeps one list of NTP servers and a time zone per site and aligns
a device that differs (NetOrk/netork#2360). A Windows host takes part
through w32time and its time zone, in one PowerShell script per read.
The servers and the mode are read from w32time's registry values, group
policy's first, not from w32tm /query /configuration, whose text is in
the host's language; synchronised is the leap indicator on the first
line of w32tm /query /status, which reads the same in any language. The
servers are written the way w32tm /config /manualpeerlist
/syncfromflags:manual writes them (NtpServer with 0x8, Type NTP),
followed by w32tm /config /update: no value passes a native command
line, whose quoting Windows PowerShell 5.1 mangles. A domain member that
takes its time from the domain hierarchy (NT5DS, AllSync) and a host
whose w32time comes from group policy refuse the write: their time is
set elsewhere, and a local write would be overridden or break the
domain's time.
Windows keeps a Windows zone, which stands for several IANA zones, so
Europe/Vienna written would read back as Europe/Berlin and the poll
would align the host forever. The IANA name written is kept beside it
in HKLM\SOFTWARE\napalm-windows and read back while the host is still
in that Windows zone. The zone is read from the registry, which
[TimeZoneInfo]::Local caches for the life of the remote session.
The zone table is now CLDR's windowsZones.xml (release 49) both ways,
generated by tools/windows_zones.py with tzdata's links and committed
with its source and checksum; nothing is fetched at runtime. CLDR's old
names (Asia/Calcutta) read as their current ones (Asia/Kolkata).
Writes the host already has are skipped. Needs napalm-device-types
4.35.0.
Refs NetOrk/netork#2367
netOrk shows and controls every scheduled job of a host; on Windows that
is the Task Scheduler. The driver now implements napalm-device-types'
ScheduledJobsMixin over PowerShell Remoting, one script per call as every
getter does.
get_scheduled_jobs reads every task with its run info in one script
(Get-ScheduledTask, Get-ScheduledTaskInfo) as task:<path><name>, its
triggers summarised. Tasks under \Microsoft\ are the platform's, others
the admin's: Windows does not record which software installed a task.
The time zone is mapped to IANA for the common Windows zones, else None.
A reading cut short, or holding fewer tasks than it counted, raises.
manage_scheduled_job switches the task's own flag or starts it;
Start-ScheduledTask returns once the task has started, so the result says
that and no more. A disabled task, or one that refuses a start on demand,
is not offered run.
put_scheduled_job registers an application's task \<name> in the root
folder from XML, so a create and a change write the whole definition the
same way: the command runs in cmd.exe /d /s /c, the principal is SYSTEM
or a local user without a stored password (S4U), and the cron expression
becomes triggers only where Task Scheduler can say it exactly; any other
shape is refused, naming why. The description keeps the job's name and
cron expression, so the reading gives back what was written, and the
digest also covers the triggers, so a change by hand is seen.
delete_scheduled_job unregisters such a task and no other. Every write
reads the task again first, and every value goes into PowerShell
single-quoted with its quotes doubled.
Requires napalm-device-types 4.26.0.
Closes#8
netOrk runs every driver in its own containers on Python 3.12, so 3.10
and 3.11 are no longer supported or tested. requires-python, mypy and
ruff move to 3.12, along with what ruff's pyupgrade rules then rewrite.
- CI moves to .gitea/workflows/ci.yml and calls the shared driver workflow
of NAPALM/driver-standard; .github/ is gone.
- requires-python >=3.10 (napalm-device-types needs it), LICENSE file,
py.typed, setuptools>=77 with the SPDX license string, Issues and
Changelog links on git.netork.io, napalm-device-types>=4.21.1 from PyPI,
floors on the dev extra.
- mypy strict for the whole package, no module exempt: optional_args is
dict[str, Any] | None.
- tests/quality_baseline.json records get_facts and get_route_to, over
complexity 10. Coverage floor 95 % (measured 95.67 %).
- CHANGELOG.md in Keep a Changelog form; the README says no host output is
recorded yet, links napalm-device-types in the NAPALM org and pypsrp on
PyPI.
- get_route_to: "0.0.0.0" and "::" are the unspecified next hop of an
on-link route as the host reports it, not an address anything binds to
(nosec B104).
Mechanical: the rule set every NAPALM driver uses (E, F, I, UP, B at line
length 100, Python 3.10), with E501 off under tests/. The code was already
formatted and clean under it; what ruff cannot fix comes in the next commit.
The same job as napalm-fritzbox and napalm-opnsense: Python 3.10, 3.11 and
3.12, pytest, then wheel and sdist. napalm-device-types comes from
git.netork.io first, because PyPI has an unrelated package of that name.
One script: Get-NetTCPConnection -State Listen, Get-NetUDPEndpoint, the
processes holding them and Win32_Service's PIDs. A process running one
service names it; a shared svchost runs several, and which of them holds
the socket Windows does not say, so it names none. http.sys sockets
(WinRM, IIS, SMB) belong to the System process.
The fixture is synthetic: no Windows host was at hand. tools/harvest.py
records the real output. For netOrk#673.