From d4b0c9497d85ca653ed1f0116e276b7f72370863 Mon Sep 17 00:00:00 2001 From: Marsell Kukuljevic Date: Thu, 7 Nov 2024 15:54:45 +0100 Subject: [PATCH] Add support for proxy to Azure plugin. --- check_mk-azure/azure-spearhead-0.1.2.mkp | Bin 5369 -> 0 bytes check_mk-azure/azure-spearhead-0.2.0.mkp | Bin 0 -> 5544 bytes .../base/plugins/agent_based/azure_common.py | 4 +- .../agents/special/agent_azure_common | 56 +++++++++++------- .../agents/special/agent_azure_defender | 2 +- .../agents/special/agent_azure_firewall | 2 +- .../agents/special/agent_azure_keyvault | 2 +- .../share/check_mk/checks/agent_azure_common | 3 +- .../check_mk/web/plugins/wato/azure_common.py | 7 +++ 9 files changed, 47 insertions(+), 29 deletions(-) delete mode 100755 check_mk-azure/azure-spearhead-0.1.2.mkp create mode 100755 check_mk-azure/azure-spearhead-0.2.0.mkp diff --git a/check_mk-azure/azure-spearhead-0.1.2.mkp b/check_mk-azure/azure-spearhead-0.1.2.mkp deleted file mode 100755 index 15b940e60c7a11f35c77dae7496b8c22c28075c2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5369 zcmaKvWl$7=x5a5B7ipzo=`KkDX$2M+q#GobT1hEcIu=psa!EmCrJG$^T3WihyK~=v z-n@CA-n@)UAOk#XW%5AF=m^Xtkc0fBV4r zveD5AmvR5#1cPmeIr6>)WP4wdll#gMx?K})5E3>oa2G$UW3v|g%2G7e@kf@HYjD>deGIi6a}H5kRotB8modt*8UlbQ3W+CzDA zo!Z-I-)O!r52hbLGQSNrq-yJ$1RJxO`*uMm7B{PXlusxX-^7fsEXYXM+X2YPb*)8E zWj$Ms8Y&wXviVbX^-TTUziz|=rLy`0I3(I6ozj6BT0kM}qDv|-#=49_C_<=%6){VP zuPkOTSLBzM@fa8d2I}$A=Au+*vBTN)?;KV)ygHQF%_1a#=UX*P%ZHzO$?N2}CCRNL z&OXrvA~ntn8O9GHBw?*)1M zINSVCmVp6a^KW`C-5#A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^?>gx+S8}K%1(Sm}DuB=Pe$qSc=&+BFfR}P^j z%4^rAV@ zcHM~l)7_#c8!7WljBBn6TRODj@ifXiQbd4@G~WKVW^{czF?tVQ7-wyj8aH9Dx%|L) zlUaCapz?Vp-O~xU>sq%ibE8GiWs3oJeP#q8Kg9E0kP3eBw`}nssHXP Z|JQ;3PnG!(x&|F%4)@~#SjSjc{{>8;Z*%|v diff --git a/check_mk-azure/azure-spearhead-0.2.0.mkp b/check_mk-azure/azure-spearhead-0.2.0.mkp new file mode 100755 index 0000000000000000000000000000000000000000..be07ed8e3d1f7a800bb480df291e7b0a17fa1aff GIT binary patch literal 5544 zcmai%RZtrYqJ?oS?p~}AJQTO!4u#?p+>2ABXmN+&P#lUCw-yMlr8pFd6Fff}ptxl3 z-iNzSJNNC(oVRc0%zTF_5eH>^p2ralc`E(EXYG5-eVt|a(D&GR`n}Q0%;c*q!sTSlKk#Fk^&y65+Ro#o#vO}dVD=P%Im@Z|xp%jLgi`cd zb-#0m?|xlB=Vv`69p<}f*IA#yi;x2cy}%RLfq3a z7g%_BrpqqI7a7GSGb3f42lp=+wo^=_3xE%g0X_4q!8^I?ULu9x7k-l!(%@nNU((U| zbN`-vZ|#d9=`5d_Ete8?Ii(_ge?%A}r5YI}a2-I06=3qo29}13`gs1NHUxWIK^_42 zC{B?Vb1%)!NFo~~uRC8|O8dB}v2UUYUB59<1X4PM4QwqwJD z-_wf5usOkCq)I*l-v&bWu|Lu(U*&36;(jYy(xHn1a0$0%;pHh=7rZ`D)F1T{Qz*)Z zMNJB%iy!r-ET3D#aPg$9YKC}HSqXB>=~zz#Vamgut^jXf5plIlL%EOU0O`^kW(xl} z4&0JW#{jHtlckQS$-9#sENe1t759wzcGU98jd(i%!$4NLEyZEELV#E*%kb|jr8z97wkzAVBrXklgzVe&Wjb9|DuN0N`s(W{dV|1&Wd76^ zJ3)uz3y-kz1?Ud0-YrT&GRE`P2=oUId>BJdF@jBzkp_qy%>ppKBuEPtupW?$!^yr6 z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5Cb#g0nKM%oBkKXmN$YVk zHGJoDB}Z{e$-6E>ex^1TOfvqI9r#9JiA8C@@=J{QEUy)>Q`R|If(kSKk$*8B2N?1A z=euERCj-L+yTA{aTg`<7!#!4otLXVxj;(KfqCS&?RR3fb4JGv1(PQt5JxSAJ+s-6Q zBlB0T+S?UX%sCz4i3yAH81M!Ip_jrP+j0?{0Gz%v0!q48Tj{%hD8Xxy;tG-?%=w{R zqLwT=42>HhGmCAvoPoW)nqH~WMiXSIWrxQf*gwrQo<7{zpB2!ow~{miup@w5CC?-6 z7o-lxNi?+MsuT?CHk^pc!#141i8=6urhgdRqWN0`R!mb27V6@D8jgtYJ=qnl@pawS yqjfC44kkt=@7bZllkFUaBEoz-bshUYReAhpqyOzH+&K;)(fP83MNkkZDE|VbSFBF} literal 0 HcmV?d00001 diff --git a/check_mk-azure/local/lib/check_mk/base/plugins/agent_based/azure_common.py b/check_mk-azure/local/lib/check_mk/base/plugins/agent_based/azure_common.py index 7390385..820fcee 100644 --- a/check_mk-azure/local/lib/check_mk/base/plugins/agent_based/azure_common.py +++ b/check_mk-azure/local/lib/check_mk/base/plugins/agent_based/azure_common.py @@ -95,7 +95,7 @@ def check_keyvault(item, params, section): state=State.UNKNOWN, summary="Capacity: N/A", ) - + if latency is not None: yield Result( @@ -112,7 +112,7 @@ def check_keyvault(item, params, section): state=State.UNKNOWN, summary="Latency: N/A", ) - + if hits is not None: yield Metric( diff --git a/check_mk-azure/local/share/check_mk/agents/special/agent_azure_common b/check_mk-azure/local/share/check_mk/agents/special/agent_azure_common index e4567fb..ede24c9 100755 --- a/check_mk-azure/local/share/check_mk/agents/special/agent_azure_common +++ b/check_mk-azure/local/share/check_mk/agents/special/agent_azure_common @@ -38,7 +38,14 @@ def get_url(req, default): raise e -def get_token(tenant, username, password): +def set_proxy(req, proxy): + if proxy is None or proxy == '': + return + match = re.match('(https?)://(.+?)/?$', proxy, re.I) + req.set_proxy(match[2], match[1].lower()) + + +def get_token(tenant, username, password, proxy): data = parse.urlencode({ 'username': username, 'password': password, @@ -52,6 +59,7 @@ def get_token(tenant, username, password): req = request.Request(f'https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token', data=str.encode(data)) + set_proxy(req, proxy) res = get_url(req, None) if res is None: @@ -62,31 +70,32 @@ def get_token(tenant, username, password): return token -def get_json(token, path, version='2023-07-01'): +def get_json(token, proxy, path, version='2023-07-01'): url = f"https://management.azure.com{path}{'?' in path and '&' or '?'}api-version={version}" req = request.Request(url, headers={'Authorization': f'Bearer {token}'}) + set_proxy(req, proxy) res = get_url(req, "[]") data = json.loads(res) return data['value'] -def list_subscriptions(token): - return get_json(token, '/subscriptions') +def list_subscriptions(token, proxy): + return get_json(token, proxy, '/subscriptions') -def list_vaults(token, subscription): - return get_json(token, f'/subscriptions/{subscription}/resources?$filter=resourceType%20eq%20%27Microsoft.KeyVault%2Fvaults%27') +def list_vaults(token, proxy, subscription): + return get_json(token, proxy, f'/subscriptions/{subscription}/resources?$filter=resourceType%20eq%20%27Microsoft.KeyVault%2Fvaults%27') -def list_firewalls(token, subscription): - return get_json(token, f'/subscriptions/{subscription}/resources?$filter=resourceType%20eq%20%27Microsoft.Network%2FazureFirewalls%27') +def list_firewalls(token, proxy, subscription): + return get_json(token, proxy, f'/subscriptions/{subscription}/resources?$filter=resourceType%20eq%20%27Microsoft.Network%2FazureFirewalls%27') -def list_defender_alerts(token, subscription): - return get_json(token, f'/subscriptions/{subscription}/providers/Microsoft.Security/alerts', '2022-01-01') +def list_defender_alerts(token, proxy, subscription): + return get_json(token, proxy, f'/subscriptions/{subscription}/providers/Microsoft.Security/alerts', '2022-01-01') -def get_recent_metrics(token, path, metrics): +def get_recent_metrics(token, proxy, path, metrics): end = datetime.now() start = end - timedelta(minutes=2) @@ -94,7 +103,7 @@ def get_recent_metrics(token, path, metrics): end_str = end.isoformat().split('.')[0] + 'Z' metrics_str = ','.join(metrics) - return get_json(token, f'{path}/providers/microsoft.insights/metrics?metricnames={metrics_str}×pan={start_str}/{end_str}', '2023-10-01') + return get_json(token, proxy, f'{path}/providers/microsoft.insights/metrics?metricnames={metrics_str}×pan={start_str}/{end_str}', '2023-10-01') def metrics_to_lookup(metrics): @@ -112,25 +121,26 @@ def metrics_to_lookup(metrics): def get_args(argv): - if len(argv) != 5 or argv[1] not in ['keyvault', 'firewall', 'defender']: - print(f"{sys.argv[0]} ", file=sys.stderr) + if (len(argv) != 5 and len(argv) != 6) or argv[1] not in ['keyvault', 'firewall', 'defender']: + print(f"{sys.argv[0]} ", file=sys.stderr) print(f"Valid commands are: 'keyvault', 'firewall', 'defender'", file=sys.stderr) + print(f"Proxy is an optional argument", file=sys.stderr) exit(1) - return argv[1], argv[2], argv[3], argv[4] + return argv[1], argv[2], argv[3], argv[4], (argv[5] if len(argv) == 6 else None) def print_json(obj): print(json.dumps(obj)) -command, tenant, username, password = get_args(sys.argv) -token = get_token(tenant, username, password) +command, tenant, username, password, proxy = get_args(sys.argv) +token = get_token(tenant, username, password, proxy) -for subscription in list_subscriptions(token): +for subscription in list_subscriptions(token, proxy): subscription_id = subscription['subscriptionId'] if command == 'defender': - for alert in list_defender_alerts(token, subscription_id): + for alert in list_defender_alerts(token, proxy, subscription_id): properties = alert['properties'] status = properties['status'] @@ -152,8 +162,8 @@ for subscription in list_subscriptions(token): }) elif command == 'firewall': - for firewall in list_firewalls(token, subscription_id): - metrics = get_recent_metrics(token, firewall['id'], FIREWALL_METRICS) + for firewall in list_firewalls(token, proxy, subscription_id): + metrics = get_recent_metrics(token, proxy, firewall['id'], FIREWALL_METRICS) print_json({ 'type': command, 'name': firewall['name'], @@ -163,8 +173,8 @@ for subscription in list_subscriptions(token): }) elif command == 'keyvault': - for vault in list_vaults(token, subscription_id): - metrics = get_recent_metrics(token, vault['id'], VAULT_METRICS) + for vault in list_vaults(token, proxy, subscription_id): + metrics = get_recent_metrics(token, proxy, vault['id'], VAULT_METRICS) print_json({ 'type': command, 'name': vault['name'], diff --git a/check_mk-azure/local/share/check_mk/agents/special/agent_azure_defender b/check_mk-azure/local/share/check_mk/agents/special/agent_azure_defender index 3f394bf..57d7514 100755 --- a/check_mk-azure/local/share/check_mk/agents/special/agent_azure_defender +++ b/check_mk-azure/local/share/check_mk/agents/special/agent_azure_defender @@ -3,4 +3,4 @@ echo '<<>>' dir=$(dirname -- "${BASH_SOURCE[0]}") -"$dir"/agent_azure_common defender "$1" "$2" "$3" +"$dir"/agent_azure_common defender "$1" "$2" "$3" "$4" diff --git a/check_mk-azure/local/share/check_mk/agents/special/agent_azure_firewall b/check_mk-azure/local/share/check_mk/agents/special/agent_azure_firewall index a339a41..6091096 100755 --- a/check_mk-azure/local/share/check_mk/agents/special/agent_azure_firewall +++ b/check_mk-azure/local/share/check_mk/agents/special/agent_azure_firewall @@ -3,4 +3,4 @@ echo '<<>>' dir=$(dirname -- "${BASH_SOURCE[0]}") -"$dir"/agent_azure_common firewall "$1" "$2" "$3" +"$dir"/agent_azure_common firewall "$1" "$2" "$3" "$4" diff --git a/check_mk-azure/local/share/check_mk/agents/special/agent_azure_keyvault b/check_mk-azure/local/share/check_mk/agents/special/agent_azure_keyvault index c040036..65d9793 100755 --- a/check_mk-azure/local/share/check_mk/agents/special/agent_azure_keyvault +++ b/check_mk-azure/local/share/check_mk/agents/special/agent_azure_keyvault @@ -3,4 +3,4 @@ echo '<<>>' dir=$(dirname -- "${BASH_SOURCE[0]}") -"$dir"/agent_azure_common keyvault "$1" "$2" "$3" +"$dir"/agent_azure_common keyvault "$1" "$2" "$3" "$4" diff --git a/check_mk-azure/local/share/check_mk/checks/agent_azure_common b/check_mk-azure/local/share/check_mk/checks/agent_azure_common index 8fc1f47..b259c6d 100644 --- a/check_mk-azure/local/share/check_mk/checks/agent_azure_common +++ b/check_mk-azure/local/share/check_mk/checks/agent_azure_common @@ -16,7 +16,8 @@ def agent_azure_args(params, hostname, ipaddress): return [ params["tenant"], params["username"], - password + password, + params.get("proxy") or "" # optional ] special_agent_info["azure_keyvault"] = agent_azure_args diff --git a/check_mk-azure/local/share/check_mk/web/plugins/wato/azure_common.py b/check_mk-azure/local/share/check_mk/web/plugins/wato/azure_common.py index a23173c..dcecf43 100644 --- a/check_mk-azure/local/share/check_mk/web/plugins/wato/azure_common.py +++ b/check_mk-azure/local/share/check_mk/web/plugins/wato/azure_common.py @@ -48,6 +48,13 @@ def _discovery(title): allow_empty=False, ), ), + ( + "proxy", + TextInput( + title=_("Proxy"), + ), + ), + ], )