Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collect Windows patch/update versions #267

Closed
muralikanagala opened this issue Oct 29, 2018 · 14 comments
Closed

Collect Windows patch/update versions #267

muralikanagala opened this issue Oct 29, 2018 · 14 comments

Comments

@muralikanagala
Copy link

Hi there,

Is there a way to collect the current patch/update version of Windows using win32_quickfixengineering?
This would be really helpful in managing and monitoring the updates.

get-wmiobject -class win32_quickfixengineering

Thank you!

@carlpett
Copy link
Collaborator

Hi @muralikanagala!
Agree that being able to see versions and/or some Windows Update info would be really useful. However, if I recall correctly, we've looked into this class and found it lacking in some way... I don't recall the specifics, but I think that it only covered hotfixes (and you typically don't install those everywhere, mostly manually on a specific subset of machines) rather than all updates?
But I don't find the details, so I may misremember. What data do you get from the class on your machines that would be useful? And what versions of Windows have you tried on?

@muralikanagala
Copy link
Author

Hi @carlpett,
Thanks for the quick response!
My requirement is to get the current patch versions using wmi exporter. A metric like the below one would be useful.

wmi_patch_version{instance="my_instance", version="patch_version"} 1

Thanks!

@pete-leese
Copy link

Maybe a better option is to use write a powershell script that creates a textfile output that can be pulled from the textfile collector for WMI Exporter.

Maybe this script is a good starting point;

https://gallery.technet.microsoft.com/scriptcenter/PowerShell-script-to-list-0955fe87

@muralikanagala
Copy link
Author

Thank you!

@kaffarell
Copy link
Contributor

This has already been discussed @breed808

@breed808
Copy link
Contributor

Resolved in #1051

@caidingyu
Copy link

Unsure if I understand it correctly...it looks like #1051 didn't really resolve the initial request in this ticket, as it doesn't export revision number, which patch/update info is supposed to tie with.

The major version, minor version and build number exported by #1051 cannot be used to monitor patching status.

@breed808
Copy link
Contributor

I think there's a little ambiguity in this issue on the required metric (revision/patch number), but I agree additional info for patching would be desirable.

The textfile collector method described above is still a valid option, though if a metric source (WMI, perflib, etc) for the revision number is available we could integrate it into the exporter.

@breed808 breed808 reopened this Oct 21, 2022
@sascha-wi
Copy link

Can somebody clarify how it would be possible to gather update/version status for windows hosts?
https://gallery.technet.microsoft.com/scriptcenter/PowerShell-script-to-list-0955fe87
Doesn't lead nowhere for me. Basically we are looking for an alert which tells us how many updates are available to be installed.

@breed808
Copy link
Contributor

The windows_exporter doesn't provide the metrics you're asking for, though if you can find a suitable metric source we could add those to the exporter.

@sentenzadorval
Copy link

sentenzadorval commented May 20, 2023

@breed808 ,

On windows10, I'm able to get the list of KB installed with:

Get-WmiObject -Class win32_quickfixengineering | Select CSName, InstalledOn, Description, HotFixID, Caption,InstalledBy,ServicePackInEffect

And get the list of installed "products" with:

Get-WmiObject -Class win32_product | Select __SERVER, IdentifyingNumber, InstallDate, Caption, Vendor, Version, LocalPackage, InstallState

Would that be a suitable source?

Copy link

This issue has been marked as stale because it has been open for 90 days with no activity. This thread will be automatically closed in 30 days if no further activity occurs.

@github-actions github-actions bot added the Stale label Nov 26, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 28, 2023
@Shivam327
Copy link

@breed808 ,

On windows10, I'm able to get the list of KB installed with:

Get-WmiObject -Class win32_quickfixengineering | Select CSName, InstalledOn, Description, HotFixID, Caption,InstalledBy,ServicePackInEffect

And get the list of installed "products" with:

Get-WmiObject -Class win32_product | Select __SERVER, IdentifyingNumber, InstallDate, Caption, Vendor, Version, LocalPackage, InstallState

Would that be a suitable source?

Did You find any solution for the same ??

@caidingyu
Copy link

My solution or workaround is to create a scheduled task to invoke a PS script to retrieve the revision number (UBR value) from the register and write into a text file to be exposed via textfile collector.

The PS command to retrieve UBR value is (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion').UBR. (Reference: https://learn.microsoft.com/en-us/answers/questions/747547/getting-windows-version-including-full-build-numbe)

The full PS script for scheduled task to retrieve UBR and write to text prom:

# Text file name (must with .prom extension) in the default location of textfile collector.
$PromFile = "C:\Program Files\windows_exporter\textfile_inputs\os.prom"

# Metric name for the UBR info
$MetricName = "windows_os_info_ubr"

# Retrieve UBR info from registry key
$UBR = (Get-CimInstance Win32_OperatingSystem).version + "." + (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion').UBR


# If the file does not exist, create it and add initial metric info
if (-not(Test-Path -Path $PromFile -PathType Leaf)) {
    try {
        # Create file
        $null = New-Item -ItemType File -Path $PromFile -Force -ErrorAction Stop

        # Metric help
        $PromContent = "# HELP $MetricName Windows OS Update Build Revision.`n"
        $PromContent += "# TYPE $MetricName gauge`n"

        # Initial metric info
        $PromContent += "$MetricName{ubr=`"$UBR`"} 1`n"

        # Write file content
        Set-Content -Path $PromFile -Encoding Ascii -NoNewline -Value $PromContent
    }
    catch {
        throw $_.Exception.Message
    }
}
# If the file already exists, update it with the latest metric
else {
    try {
        # Get file content of the existing prom file
        $PromContent = Get-Content -Path $PromFile

        # Update the metric with the latest UBR info
        $PromContent -replace "^$MetricName.*$","$MetricName{ubr=`"$UBR`"} 1" | Set-Content -Path $PromFile -Encoding Ascii
    }
    catch {
        throw $_.Exception.Message
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants