Skip to content

[monitoring-template] feat(sqlserver): add database account expiry metrics (#3737)#4141

Merged
tomsun28 merged 3 commits into
apache:masterfrom
neon-hippo:add-sqlserver-account-expiry
May 24, 2026
Merged

[monitoring-template] feat(sqlserver): add database account expiry metrics (#3737)#4141
tomsun28 merged 3 commits into
apache:masterfrom
neon-hippo:add-sqlserver-account-expiry

Conversation

@neon-hippo

Copy link
Copy Markdown
Contributor

[monitoring-template] feat(sqlserver): add database account expiry metrics

Adds an account_expiry metric group to the SQL Server monitoring template, matching the existing MySQL implementation.

Query

SELECT name AS login_name,
  ISNULL(LOGINPROPERTY(name, "DaysUntilExpiration"), -1) AS days_left,
  CASE LOGINPROPERTY(name, "IsExpired") WHEN 1 THEN "Y" ELSE "N" END AS password_expired,
  CASE is_disabled WHEN 1 THEN "Y" ELSE "N" END AS is_disabled
FROM sys.sql_logins
WHERE type_desc = "SQL_LOGIN";

What is Included

  • app-sqlserver.yml — new account_expiry metric group (priority 100, multiRow)
  • SqlServerJdbcTemplateIntegrationTest — 34 tests across SQL Server 2017, 2019, 2022, and 2025
  • pom.xmlmssql-jdbc test dependency

Design Decisions

  • Uses CASE WHEN returning Y/N instead of raw CAST AS VARCHAR — matches MySQL mysql.user.password_expired format and avoids implicit VARCHAR lengths

Permissions Required

GRANT VIEW SERVER STATE TO [monitoring_user];
GRANT VIEW ANY DEFINITION TO [monitoring_user];

Equivalent to the MySQL implementation which requires SELECT ON mysql.*.

Compatibility

Version Status
SQL Server 2025 (17.0.4045.5, CU5) ✅ Tested
SQL Server 2022 (16.x) ✅ Tested
SQL Server 2019 (15.x) ✅ Tested
SQL Server 2017 (14.x) ✅ Tested
SQL Server 2016 ⚠️ Not tested — no Linux container image on MCR

All three catalog objects (sys.sql_logins, LOGINPROPERTY("DaysUntilExpiration"), LOGINPROPERTY("IsExpired")) are documented in Microsoft Learn for SQL Server 2025 with no deprecation warnings.

Known Limitation

HertzBeat hardcodes a 1,000-row limit for multiRow queries. Servers with >1,000 SQL logins will see truncated results. This is a platform limitation, not specific to this template.

References


🤖 This patch was developed with assistance from DeepSeek-v4-pro.

@tomsun28 tomsun28 merged commit 70ef12d into apache:master May 24, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task] Add database account expiry monitoring metrics

3 participants