From c3a860a1324e55f6350847f9272d57933999a540 Mon Sep 17 00:00:00 2001 From: dkairu Date: Mon, 13 May 2024 15:09:03 -0400 Subject: [PATCH] Updated the MSSQL drive to use an Azure to provide flexibility of using Azure Tokens instead of user pass --- ...naged-Instance-active-directory-tokens.yml | 25 +++++++++++++++++++ ...re-SQL-Managed-Instance-user-password.yml} | 0 go.mod | 4 +++ go.sum | 4 +++ internal/inputs/database.go | 2 +- internal/load/load.go | 2 +- 6 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 examples/Azure-SQL-Managed-Instance-active-directory-tokens.yml rename examples/{Azure-SQL-Managed-Instance.yml => Azure-SQL-Managed-Instance-user-password.yml} (100%) diff --git a/examples/Azure-SQL-Managed-Instance-active-directory-tokens.yml b/examples/Azure-SQL-Managed-Instance-active-directory-tokens.yml new file mode 100644 index 00000000..42245fc9 --- /dev/null +++ b/examples/Azure-SQL-Managed-Instance-active-directory-tokens.yml @@ -0,0 +1,25 @@ +# This custom integration uses flex to query Azure SQL for custom metrics. Notes are below. +# +# Azure Entra ID(formerly Active Directory) authentication uses temporary authentication tokens to authenticate and connect to your Azure SQL database. +# The Azure SQL database needs to be configured to use Entra ID admin service principal as a way to connect. +# You can authenticate using either fedauth=ActiveDirectoryServicePrincipal or fedauth=ActiveDirectoryApplication +# Which authenticates using an Azure Active Directory application client ID and client secret or certificate. +# The certifcate format should be clientcertpath=;password= +# Other options including using Azure Managed Identity or Active directory passwords are also available and are explained here https://github.com/denisenkom/go-mssqldb?tab=readme-ov-file#azure-active-directory-authentication +--- +integrations: + - name: nri-flex + # interval: 30s + config: + name: AzureSQLDbFlex + apis: + - database: sqlserver + db_conn: server=azure.database.windows.net;user id=;password=;database=master;fedauth=ActiveDirectoryServicePrincipal + logging: + open: true + custom_attributes: # applies to all queries + host: azure.database.windows.net + db_async: true # process queries async + db_queries: + - name: AzureSQLCustomLogSpace + run: DBCC SQLPERF(LOGSPACE); \ No newline at end of file diff --git a/examples/Azure-SQL-Managed-Instance.yml b/examples/Azure-SQL-Managed-Instance-user-password.yml similarity index 100% rename from examples/Azure-SQL-Managed-Instance.yml rename to examples/Azure-SQL-Managed-Instance-user-password.yml diff --git a/go.mod b/go.mod index 30c7cf96..1d8b812a 100644 --- a/go.mod +++ b/go.mod @@ -38,6 +38,9 @@ require ( require ( dario.cat/mergo v1.0.0 // indirect filippo.io/edwards25519 v1.1.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/azcore v0.19.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.11.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/internal v0.7.0 // indirect github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect @@ -77,6 +80,7 @@ require ( github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/image-spec v1.0.2 // indirect github.com/pjbgf/sha1cd v0.3.0 // indirect + github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect github.com/prometheus/procfs v0.9.0 // indirect diff --git a/go.sum b/go.sum index 0d4ed00e..99d3bd83 100644 --- a/go.sum +++ b/go.sum @@ -40,8 +40,11 @@ dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= +github.com/Azure/azure-sdk-for-go/sdk/azcore v0.19.0 h1:lhSJz9RMbJcTgxifR1hUNJnn6CNYtbgEDtQV22/9RBA= github.com/Azure/azure-sdk-for-go/sdk/azcore v0.19.0/go.mod h1:h6H6c8enJmmocHUbLiiGY6sx7f9i+X3m1CHdd5c6Rdw= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.11.0 h1:OYa9vmRX2XC5GXRAzeggG12sF/z5D9Ahtdm9EJ00WN4= github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.11.0/go.mod h1:HcM1YX14R7CJcghJGOYCgdezslRSVzqwLf/q+4Y2r/0= +github.com/Azure/azure-sdk-for-go/sdk/internal v0.7.0 h1:v9p9TfTbf7AwNb5NYQt7hI41IfPoLFiFkLtb+bmGjT0= github.com/Azure/azure-sdk-for-go/sdk/internal v0.7.0/go.mod h1:yqy467j36fJxcRV2TzfVZ1pCb5vxm4BtZPUdYWe/Xo8= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= @@ -274,6 +277,7 @@ github.com/parnurzeal/gorequest v0.2.15 h1:oPjDCsF5IkD4gUk6vIgsxYNaSgvAnIh1EJeRO github.com/parnurzeal/gorequest v0.2.15/go.mod h1:3Kh2QUMJoqw3icWAecsyzkpY7UzRfDhbRdTjtNwNiUE= github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= +github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 h1:49lOXmGaUpV9Fz3gd7TFZY106KVlPVa5jcYD1gaQf98= github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= diff --git a/internal/inputs/database.go b/internal/inputs/database.go index c2b17a68..7a472773 100644 --- a/internal/inputs/database.go +++ b/internal/inputs/database.go @@ -27,7 +27,7 @@ import ( _ "github.com/MonetDB/MonetDB-Go/src" //MonetDB // _ "github.com/SAP/go-ase" //Sybase _ "github.com/SAP/go-hdb/driver" //SAP HANA - _ "github.com/denisenkom/go-mssqldb" //mssql | sql-server + _ "github.com/denisenkom/go-mssqldb/azuread" //mssql | sql-server _ "github.com/go-sql-driver/mysql" //mysql _ "github.com/lib/pq" //postgres _ "github.com/sijms/go-ora/v2" //Oracle diff --git a/internal/load/load.go b/internal/load/load.go index 91f8bfb0..335fd49e 100644 --- a/internal/load/load.go +++ b/internal/load/load.go @@ -116,7 +116,7 @@ const ( DefaultPingTimeout = 5000 // 5 seconds DefaultHANA = "hdb" DefaultPostgres = "postgres" - DefaultMSSQLServer = "sqlserver" + DefaultMSSQLServer = "azuresql" DefaultMySQL = "mysql" DefaultOracle = "oracle" // DefaultSybase = "ase"