@@ -76,7 +76,15 @@ def check_or_fix(fix=False):
7676 if not working_hosts :
7777 working_hosts = set (c ['http_host_list' ])
7878
79- update_records (c , working_hosts )
79+ message = 'OFM loadbalancer FIX found no working hosts, reverting to full list!'
80+ print (message )
81+ telegram_send_message (message , c ['telegram_token' ], c ['telegram_chat_id' ])
82+
83+ updated = update_records (c , working_hosts )
84+ if updated :
85+ message = f'OFM loadbalancer FIX modified records, new records: { working_hosts } '
86+ print (message )
87+ telegram_send_message (message , c ['telegram_token' ], c ['telegram_chat_id' ])
8088
8189
8290def run_area (c , area ):
@@ -117,14 +125,16 @@ def get_target_version(area):
117125 return response .text .strip ()
118126
119127
120- def update_records (c , working_hosts ):
128+ def update_records (c , working_hosts ) -> bool :
121129 config = dotenv_values ('/data/ofm/config/cloudflare.ini' )
122130 cloudflare_api_token = config ['dns_cloudflare_api_token' ]
123131
124132 domain = '.' .join (c ['domain_ledns' ].split ('.' )[- 2 :])
125133 zone_id = get_zone_id (domain , cloudflare_api_token = cloudflare_api_token )
126134
127- set_records_round_robin (
135+ updated = False
136+
137+ updated |= set_records_round_robin (
128138 zone_id = zone_id ,
129139 name = c ['domain_ledns' ],
130140 host_ip_set = working_hosts ,
@@ -134,7 +144,7 @@ def update_records(c, working_hosts):
134144 cloudflare_api_token = cloudflare_api_token ,
135145 )
136146
137- set_records_round_robin (
147+ updated |= set_records_round_robin (
138148 zone_id = zone_id ,
139149 name = c ['domain_cf' ],
140150 host_ip_set = working_hosts ,
@@ -143,6 +153,8 @@ def update_records(c, working_hosts):
143153 cloudflare_api_token = cloudflare_api_token ,
144154 )
145155
156+ return updated
157+
146158
147159if __name__ == '__main__' :
148160 cli ()
0 commit comments