From 1b235d080f7a69cb95511f52f3c60b6636563590 Mon Sep 17 00:00:00 2001 From: Robert Sander Date: Mon, 9 Sep 2024 16:50:50 +0200 Subject: [PATCH] adds script container_piggyback_translation adds rules to prefix container names with Docker node name (hostname) --- helper/bin/container_piggyback_translation.py | 84 ++++++++++++++++++ helper/helper-0.14.0.mkp | Bin 3504 -> 0 bytes helper/helper-0.15.0.mkp | Bin 0 -> 3959 bytes 3 files changed, 84 insertions(+) create mode 100755 helper/bin/container_piggyback_translation.py delete mode 100644 helper/helper-0.14.0.mkp create mode 100644 helper/helper-0.15.0.mkp diff --git a/helper/bin/container_piggyback_translation.py b/helper/bin/container_piggyback_translation.py new file mode 100755 index 00000000..c0246dfb --- /dev/null +++ b/helper/bin/container_piggyback_translation.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 +# -*- encoding: utf-8; py-indent-offset: 4 -*- + +# +# (C) 2017 Heinlein Support GmbH +# Robert Sander +# + +ruleset_name = 'piggyback_translation' +tag_string = 'generated by container_piggyback_translation' + +import argparse +import checkmkapi +from pprint import pprint + +parser = argparse.ArgumentParser() +parser.add_argument('-s', '--url', + required=False, + help='URL to Check_MK site') +parser.add_argument('-u', '--username', + required=False, + help='name of the Automation user') +parser.add_argument('-p', '--password', + required=False) +parser.add_argument('-i', '--site', + required=False) +args = parser.parse_args() + +mapi = checkmkapi.MultisiteAPI(args.url, args.username, args.password) +wato = checkmkapi.CMKRESTAPI(args.url, args.username, args.password) + +if args.site: + resp = mapi.view(view_name='servicedesc', service='Docker node info', filled_in='filter', site=args.site) +else: + resp = mapi.view(view_name='servicedesc', service='Docker node info') +hosts = list(map(lambda x: x['host'], resp)) + +rules, etag = wato.get_rules(ruleset_name) + +host_rules = {} +del_rules = [] + +for rule in rules['value']: + rule_id = rule['id'] + rule_ex = rule['extensions'] + rule_prop = rule_ex.get('properties', {}) + conditions = rule_ex.get('conditions', {}) + host_match = conditions.get('host_name', {}) + if len(host_match.get('match_on', [])) == 1 and host_match.get('operator', '') == 'one_of' and host_match['match_on'][0] in hosts: + host_rules[host_match['match_on'][0]] = rule_id + hosts.remove(host_match['match_on'][0]) + elif rule_prop.get('description', '') == tag_string: + del_rules.append(rule_id) + +changes = False + +for rule_id in del_rules: + print(f"Removing {rule_id}.") + wato.delete_rule(rule_id) + changes = True + +for host in hosts: + value_raw = "{'regex': [('(.+?)', '%s_\\\\1')]}" % host.replace(".", "_") + print(value_raw) + wato.create_rule( + ruleset_name, + "/", + value_raw, + conditions = { + "host_name": { + "match_on": [host], + "operator": "one_of", + }, + }, + properties = { + "disabled": False, + "description": tag_string, + }, + ) + changes = True + +if changes: + print("Activating changes.") + wato.activate() diff --git a/helper/helper-0.14.0.mkp b/helper/helper-0.14.0.mkp deleted file mode 100644 index 6d937d8a6dfce8b1bda080e5ee0f559c9ad1187f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3504 zcmV;h4NvkPiwFQ2iymeI|Lt7iZreB#&Tl^jS4AP~&XMiJc5c1r!xi1$cCp*NUfTr@ za124Q=vW(B(u$OmAjrGl3`t3pEW1w9G@CsQ(AXk}!y!4G`G%D1hl}Xok*NnX8VtlI zQ1!Fl@AnS+gHi8f*c%Rx`%pd_jd};9ckmS`W!z1m%Y*+juLKr^dDxYMNE&fdE&?1k3ww!mIg62lx6HRlswU8 z7(}k;q)C8GOU`39?sm_8zD&>Td9>=jRq{Vd@!k27&M%zRg+s464H-yhU7k?dUAc_Y zq`MUT2(ysj*fP3IQs`nk%RER? zDJO8xXt0AXp{r<3on^#0+ufnFc7v2Uj7JGY&e<)FG;~)~%wI8h?(={a6EDivG+}Bv zdUk(c_w-VG<%do}e^32{ddPBQAKAV5+Y(Rg&M(|^z5eL9#E>%gETB#ravxXpmnfvS zt%HW1CHdh0?cZ1wKAr#XoeV}5|9>)qqQ?J!4gYTlFJg>|A-#yvAqM&yELr9ynx`*V z3r~+M$~|DU^gLQ&?o_Zgb1Hhh?wAUmZ*>;k?Ep)d1_9K{=!H%061~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Q>Oyb4f{CEc16r8eUQCZUx)NYzeZHwkV-4K>tILk%_5P(uwh)KEhWHPlc;4K>tILk%_5P(uwh e)KEhWHPlc;4K>tILk%_bJm`PA+2Y**cmM#dAKxMX diff --git a/helper/helper-0.15.0.mkp b/helper/helper-0.15.0.mkp new file mode 100644 index 0000000000000000000000000000000000000000..9444f06cf74c92cb89ee56248b57400d307e4132 GIT binary patch literal 3959 zcmbu<_aoGg!vJubY>}-ad+W$ND_hAPi9^Owvgc(KnJ4$LWrVIoN5|Q+6UjKv-h1zH zHt+BAKRmy^{(=_>K}AGGGw((M>~g>MpOyy~5X4Q~z$_TBy|@ z=A}F2(esWgz&hhZlguMWI);jf8MKdDU*N_d=JgSF;uE@D*ODh>lK>NlD3ukq!JvI4!@emP~7w)Op+9jHJb8mIHZ#)WT zdw-3od@L?2e<-QPlB*F#8eEdqh?Y48U%q8>lha674aV^l&yV_;Iku}0ZJ%vxQ?G&a zM#PsOoiTu5!e-!p!h30&$AiG0w?qQS7+^pq$I{(I1}Ms30>>MX2sGvE#}Y;N%ZMvY z5*&L<#fId{|4Ic?h zT6kJ!kc7fhP>{NN@ut?WeE0_V87L^_zQQw&jejJ|WCgP5--?IC$|$`fP^A@X5C2@-03)Xd7K#5a6I0sNq9zO_-G(Fbv1P;>~UB8#I|Y->kS+IWORn$w*dh& zk5rIVH->0Yo|9ALwBw%lE=-s=Hz^ZmM~YFq^sveN>cQF-is>E#gDs6_)+Y@rNh0PC za$5LJ?bN9t4r7E}9yf;g=BjAEfA7+R+%LV=Uj}FlQa{^un7@5`^r2~C3m_POh*7E; z9}*W(Em@+!Q2t_LkSf??EE)=3=}APpN9~T`pONp5z;+-#QLMXxyJ15E#^#)qua)kO zwwe6(ssC$}M|QxVM3;3yM03}5gh8qjjQZ+O(Sdw$t53rIn4KS66-4yOQQM|^FC^}q zCNI9UpN=aV^OEPKGfTc=m%ZgMV5q@$23ZJN!8`sdBtax#`3gHd496DrZg+uU()`x0}1Y!Ta7?U$aaz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