commit 7cec9e0b1269dca5501dbac96d90c98c54b41c41
Author: Damian Johnson <[email protected]>
Date: Sun Oct 6 13:58:37 2013 -0700
Using string's format() method for notifications
Swapping from from the '%' formatting operator to string's format() method
to
improve our config and script's readability.
---
consensus_health_checker.py | 44 +++++++++++++++++++++----------------------
data/consensus_health.cfg | 32 +++++++++++++++----------------
2 files changed, 38 insertions(+), 38 deletions(-)
diff --git a/consensus_health_checker.py b/consensus_health_checker.py
index 12bb451..bf25a7a 100755
--- a/consensus_health_checker.py
+++ b/consensus_health_checker.py
@@ -53,19 +53,19 @@ class Issue(object):
self.msg = msg
@staticmethod
- def for_msg(runlevel, template, *attr):
+ def for_msg(runlevel, template, **attr):
"""
Provides an Issue for the given message from our config with any formatted
string arguments inserted.
:var str runlevel: runlevel of the issue
:param str template: base string to fetch from our config
- :param list attr: formatted string arguments
+ :param dict attr: formatted string arguments
"""
if template in CONFIG['msg']:
try:
- return Issue(runlevel, CONFIG['msg'][template] % attr)
+ return Issue(runlevel, CONFIG['msg'][template].format(**attr))
except:
log.error("Unable to apply formatted string attributes to msg.%s: %s"
% (template, attr))
else:
@@ -203,7 +203,7 @@ def missing_latest_consensus(latest_consensus, consensuses,
votes):
if stale_authorities:
runlevel = Runlevel.ERROR if len(stale_authorities) > 3 else
Runlevel.WARNING
- return Issue.for_msg(runlevel, 'MISSING_LATEST_CONSENSUS', ',
'.join(stale_authorities))
+ return Issue.for_msg(runlevel, 'MISSING_LATEST_CONSENSUS', authorities =
', '.join(stale_authorities))
def consensus_method_unsupported(latest_consensus, consensuses, votes):
@@ -216,7 +216,7 @@ def consensus_method_unsupported(latest_consensus,
consensuses, votes):
incompatible_authorities.append(authority)
if incompatible_authorities:
- return Issue.for_msg(Runlevel.WARNING, 'CONSENSUS_METHOD_UNSUPPORTED', ',
'.join(incompatible_authorities))
+ return Issue.for_msg(Runlevel.WARNING, 'CONSENSUS_METHOD_UNSUPPORTED',
authorities = ', '.join(incompatible_authorities))
def different_recommended_client_version(latest_consensus, consensuses, votes):
@@ -231,7 +231,7 @@ def different_recommended_client_version(latest_consensus,
consensuses, votes):
if differences:
if rate_limit_notice('different_recommended_versions.client', days = 1):
- return Issue.for_msg(Runlevel.NOTICE, 'DIFFERENT_RECOMMENDED_VERSION',
'client', ', '.join(differences))
+ return Issue.for_msg(Runlevel.NOTICE, 'DIFFERENT_RECOMMENDED_VERSION',
type = 'client', differences = ', '.join(differences))
def different_recommended_server_version(latest_consensus, consensuses, votes):
@@ -246,7 +246,7 @@ def different_recommended_server_version(latest_consensus,
consensuses, votes):
if differences:
if rate_limit_notice('different_recommended_versions.server', days = 1):
- return Issue.for_msg(Runlevel.NOTICE, 'DIFFERENT_RECOMMENDED_VERSION',
'server', ', '.join(differences))
+ return Issue.for_msg(Runlevel.NOTICE, 'DIFFERENT_RECOMMENDED_VERSION',
type = 'server', differences = ', '.join(differences))
def _version_difference_str(authority, consensus_versions, vote_versions):
@@ -287,7 +287,7 @@ def unknown_consensus_parameters(latest_consensus,
consensuses, votes):
unknown_entries.append('%s %s' % (authority, ' '.join(unknown_params)))
if unknown_entries:
- return Issue.for_msg(Runlevel.NOTICE, 'UNKNOWN_CONSENSUS_PARAMETERS', ',
'.join(unknown_entries))
+ return Issue.for_msg(Runlevel.NOTICE, 'UNKNOWN_CONSENSUS_PARAMETERS',
parameters = ', '.join(unknown_entries))
def vote_parameters_mismatch_consensus(latest_consensus, consensuses, votes):
@@ -306,7 +306,7 @@ def vote_parameters_mismatch_consensus(latest_consensus,
consensuses, votes):
mismatching_entries.append('%s %s' % (authority, '
'.join(mismatching_params)))
if mismatching_entries:
- return Issue.for_msg(Runlevel.NOTICE, 'MISMATCH_CONSENSUS_PARAMETERS', ',
'.join(mismatching_entries))
+ return Issue.for_msg(Runlevel.NOTICE, 'MISMATCH_CONSENSUS_PARAMETERS',
parameters = ', '.join(mismatching_entries))
def certificate_expiration(latest_consensus, consensuses, votes):
@@ -323,13 +323,13 @@ def certificate_expiration(latest_consensus, consensuses,
votes):
if (cert_expiration - current_time) <= datetime.timedelta(days = 14):
if rate_limit_notice('cert_expiration.two_weeks.%s' % authority, days =
14):
- issues.append(Issue.for_msg(Runlevel.WARNING,
'CERTIFICATE_ABOUT_TO_EXPIRE', 'two weeks', expiration_label))
+ issues.append(Issue.for_msg(Runlevel.WARNING,
'CERTIFICATE_ABOUT_TO_EXPIRE', duration = 'two weeks', authority =
expiration_label))
elif (cert_expiration - current_time) <= datetime.timedelta(days = 60):
if rate_limit_notice('cert_expiration.two_months.%s' % authority, days =
60):
- issues.append(Issue.for_msg(Runlevel.NOTICE,
'CERTIFICATE_ABOUT_TO_EXPIRE', 'two months', expiration_label))
+ issues.append(Issue.for_msg(Runlevel.NOTICE,
'CERTIFICATE_ABOUT_TO_EXPIRE', duration = 'two months', authority =
expiration_label))
elif (cert_expiration - current_time) <= datetime.timedelta(days = 90):
if rate_limit_notice('cert_expiration.three_months.%s' % authority, days
= 90):
- issues.append(Issue.for_msg(Runlevel.NOTICE,
'CERTIFICATE_ABOUT_TO_EXPIRE', 'three months', expiration_label))
+ issues.append(Issue.for_msg(Runlevel.NOTICE,
'CERTIFICATE_ABOUT_TO_EXPIRE', duration = 'three months', authority =
expiration_label))
return issues
@@ -352,7 +352,7 @@ def consensuses_have_same_votes(latest_consensus,
consensuses, votes):
authorities_missing_votes.append(authority)
if authorities_missing_votes:
- return Issue.for_msg(Runlevel.NOTICE, 'MISSING_VOTES', ',
'.join(authorities_missing_votes))
+ return Issue.for_msg(Runlevel.NOTICE, 'MISSING_VOTES', authorities = ',
'.join(authorities_missing_votes))
def has_all_signatures(latest_consensus, consensuses, votes):
@@ -378,7 +378,7 @@ def has_all_signatures(latest_consensus, consensuses,
votes):
missing_authorities.add(missing_authority)
if missing_authorities:
- return Issue.for_msg(Runlevel.NOTICE, 'MISSING_SIGNATURE', ',
'.join(missing_authorities))
+ return Issue.for_msg(Runlevel.NOTICE, 'MISSING_SIGNATURE', authorities =
', '.join(missing_authorities))
def voting_bandwidth_scanners(latest_consensus, consensuses, votes):
@@ -404,11 +404,11 @@ def voting_bandwidth_scanners(latest_consensus,
consensuses, votes):
if missing_authorities:
if rate_limit_notice('missing_bw_scanners.%s' %
'.'.join(missing_authorities), days = 1):
runlevel = Runlevel.ERROR if len(missing_authorities) > 1 else
Runlevel.WARNING
- issues.append(Issue.for_msg(runlevel, 'MISSING_BANDWIDTH_SCANNERS', ',
'.join(missing_authorities)))
+ issues.append(Issue.for_msg(runlevel, 'MISSING_BANDWIDTH_SCANNERS',
authorities = ', '.join(missing_authorities)))
if extra_authorities:
if rate_limit_notice('extra_bw_scanners.%s' % '.'.join(extra_authorities),
days = 1):
- issues.append(Issue.for_msg(Runlevel.NOTICE, 'EXTRA_BANDWIDTH_SCANNERS',
', '.join(extra_authorities)))
+ issues.append(Issue.for_msg(Runlevel.NOTICE, 'EXTRA_BANDWIDTH_SCANNERS',
authorities = ', '.join(extra_authorities)))
return issues
@@ -430,11 +430,11 @@ def has_authority_flag(latest_consensus, consensuses,
votes):
if missing_authorities:
if rate_limit_notice('missing_authorities.%s' %
'.'.join(missing_authorities), days = 7):
- issues.append(Issue.for_msg(Runlevel.WARNING, 'MISSING_AUTHORITIES', ',
'.join(missing_authorities)))
+ issues.append(Issue.for_msg(Runlevel.WARNING, 'MISSING_AUTHORITIES',
authorities = ', '.join(missing_authorities)))
if extra_authorities:
if rate_limit_notice('extra_authorities.%s' % '.'.join(extra_authorities),
days = 7):
- issues.append(Issue.for_msg(Runlevel.NOTICE, 'EXTRA_AUTHORITIES', ',
'.join(extra_authorities)))
+ issues.append(Issue.for_msg(Runlevel.NOTICE, 'EXTRA_AUTHORITIES',
authorities = ', '.join(extra_authorities)))
return issues
@@ -448,7 +448,7 @@ def has_expected_fingerprints(latest_consensus,
consensuses, votes):
expected_fingerprint = DIRECTORY_AUTHORITIES[desc.nickname].fingerprint
if desc.fingerprint != expected_fingerprint:
- issues.append(Issue.for_msg(Runlevel.ERROR, 'FINGERPRINT_MISMATCH',
desc.nickname, desc.fingerprint, expected_fingerprint))
+ issues.append(Issue.for_msg(Runlevel.ERROR, 'FINGERPRINT_MISMATCH',
authority = desc.nickname, expected = desc.fingerprint, actual =
expected_fingerprint))
return issues
@@ -468,7 +468,7 @@ def is_recommended_versions(latest_consensus, consensuses,
votes):
if outdated_authorities:
if rate_limit_notice('tor_out_of_date.%s' %
'.'.join(outdated_authorities.keys()), days = 7):
entries = ['%s (%s)' % (k, v) for k, v in outdated_authorities.items()]
- return Issue.for_msg(Runlevel.WARNING, 'TOR_OUT_OF_DATE', ',
'.join(entries))
+ return Issue.for_msg(Runlevel.WARNING, 'TOR_OUT_OF_DATE', authorities =
', '.join(entries))
def bad_exits_in_sync(latest_consensus, consensuses, votes):
@@ -492,7 +492,7 @@ def bad_exits_in_sync(latest_consensus, consensuses, votes):
with_flag = set([authority for authority, flagged in bad_exits.items() if
fingerprint in flagged])
without_flag = voting_authorities.difference(with_flag)
- issues.append(Issue.for_msg(Runlevel.NOTICE, 'BADEXIT_OUT_OF_SYNC',
fingerprint, ', '.join(with_flag), ', '.join(without_flag)))
+ issues.append(Issue.for_msg(Runlevel.NOTICE, 'BADEXIT_OUT_OF_SYNC',
fingerprint = fingerprint, with_flag = ', '.join(with_flag), without_flag = ',
'.join(without_flag)))
if issues and rate_limit_notice('bad_exits_in_sync', days = 1):
return issues
@@ -519,7 +519,7 @@ def bandwidth_authorities_in_sync(latest_consensus,
consensuses, votes):
if count > (1.2 * average) or count < (0.8 * average):
if rate_limit_notice('bandwidth_authorities_in_sync', days = 1):
entries = ['%s (%s)' % (authority, count) for authority, count in
measurement_counts.items()]
- return Issue.for_msg(Runlevel.NOTICE,
'BANDWIDTH_AUTHORITIES_OUT_OF_SYNC', ', '.join(entries))
+ return Issue.for_msg(Runlevel.NOTICE,
'BANDWIDTH_AUTHORITIES_OUT_OF_SYNC', authorities = ', '.join(entries))
break
diff --git a/data/consensus_health.cfg b/data/consensus_health.cfg
index 1fd4505..d11e4df 100644
--- a/data/consensus_health.cfg
+++ b/data/consensus_health.cfg
@@ -1,21 +1,21 @@
# message templates for notifications we send
-msg MISSING_LATEST_CONSENSUS => The consensuses published by the following
directory authorities are more than one hour old and therefore not fresh
anymore: %s
-msg CONSENSUS_METHOD_UNSUPPORTED => The following directory authorities do not
support the consensus method that the consensus uses: %s
-msg DIFFERENT_RECOMMENDED_VERSION => The following directory authorities
recommend other %s versions than the consensus: %s
-msg UNKNOWN_CONSENSUS_PARAMETERS => The following directory authorities set
unknown consensus parameters: %s
-msg MISMATCH_CONSENSUS_PARAMETERS => The following directory authorities set
conflicting consensus parameters: %s
-msg CERTIFICATE_ABOUT_TO_EXPIRE => The certificate of the following directory
authority expires within the next %s: %s
-msg MISSING_SIGNATURE => The signatures of the following, previously voting
authorities are missing from at least one consensus: %s
-msg MISSING_BANDWIDTH_SCANNERS => The following directory authorities are not
reporting bandwidth scanner results: %s
-msg EXTRA_BANDWIDTH_SCANNERS => The following directory authorities were not
expected to report bandwidth scanner results: %s
-msg MISSING_VOTES => The consensuses downloaded from the following authorities
are missing votes that are contained in consensuses downloaded from other
authorities: %s
-msg MISSING_AUTHORITIES => The following authorities are missing from the
consensus: %s
-msg EXTRA_AUTHORITIES => The following authorities were not expected in the
consensus: %s
-msg FINGERPRINT_MISMATCH => %s had a different fingerprint than we expected
(expected: %s, actual: %s)
-msg TOR_OUT_OF_DATE => The following authorities are an out of date version
of tor: %s
-msg BADEXIT_OUT_OF_SYNC => Authorities disagree about the BadExit flag for %s
(with flag: %s, without flag: %s)
-msg BANDWIDTH_AUTHORITIES_OUT_OF_SYNC => Bandwidth authorities have a
substantially different number of measured entries: %s
+msg MISSING_LATEST_CONSENSUS => The consensuses published by the following
directory authorities are more than one hour old and therefore not fresh
anymore: {authorities}
+msg CONSENSUS_METHOD_UNSUPPORTED => The following directory authorities do not
support the consensus method that the consensus uses: {authorities}
+msg DIFFERENT_RECOMMENDED_VERSION => The following directory authorities
recommend other {type} versions than the consensus: {differences}
+msg UNKNOWN_CONSENSUS_PARAMETERS => The following directory authorities set
unknown consensus parameters: {parameters}
+msg MISMATCH_CONSENSUS_PARAMETERS => The following directory authorities set
conflicting consensus parameters: {parameters}
+msg CERTIFICATE_ABOUT_TO_EXPIRE => The certificate of the following directory
authority expires within the next {duration}: {authority}
+msg MISSING_SIGNATURE => The signatures of the following, previously voting
authorities are missing from at least one consensus: {authorities}
+msg MISSING_BANDWIDTH_SCANNERS => The following directory authorities are not
reporting bandwidth scanner results: {authorities}
+msg EXTRA_BANDWIDTH_SCANNERS => The following directory authorities were not
expected to report bandwidth scanner results: {authorities}
+msg MISSING_VOTES => The consensuses downloaded from the following authorities
are missing votes that are contained in consensuses downloaded from other
authorities: {authorities}
+msg MISSING_AUTHORITIES => The following authorities are missing from the
consensus: {authorities}
+msg EXTRA_AUTHORITIES => The following authorities were not expected in the
consensus: {authorities}
+msg FINGERPRINT_MISMATCH => {authority} had a different fingerprint than we
expected (expected: {expected}, actual: {actual})
+msg TOR_OUT_OF_DATE => The following authorities are an out of date version
of tor: {authorities}
+msg BADEXIT_OUT_OF_SYNC => Authorities disagree about the BadExit flag for
{fingerprint} (with flag: {with_flag}, without flag: {without_flag})
+msg BANDWIDTH_AUTHORITIES_OUT_OF_SYNC => Bandwidth authorities have a
substantially different number of measured entries: {authorities}
# directory authorities that run bandwidth scanners
_______________________________________________
tor-commits mailing list
[email protected]
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits