diff --git a/README.md b/README.md index 6421243..3a5d74b 100644 --- a/README.md +++ b/README.md @@ -519,7 +519,9 @@ key instead of guessing from title words. Gandalf's scheme (`ticket_text.dedup_k Names are lowercased, and anything outside `a-z 0-9 _ . : -` becomes `-`. Tinker's reopen window applies per key: a match on a ticket closed under 7 days ago reopens it; an older one gets a new, -linked ticket (`new_recurrence`). `scripts/dedup_key_map.py` prints the key for each of Gandalf's open +linked ticket (`new_recurrence`). Gandalf tracks whatever ticket Tinker names, as Thor and hwmonDaemon do, +including `recurrence_noted` (a Closed ticket in a workflow set never to reopen, where Tinker adds one +note per closed period). `scripts/dedup_key_map.py` prints the key for each of Gandalf's open tickets, for Tinker's `scripts/backfill_dedup_keys.php`, so switching to keys opens no duplicates. **Thor first.** Thor correlates host health (crashes, OOM, fencing) across all three apps. Before diff --git a/monitor.py b/monitor.py index f6ba5c2..f7adec0 100644 --- a/monitor.py +++ b/monitor.py @@ -524,8 +524,6 @@ class TicketClient: self.comments_denied = False self.read_url = cfg.get('read_url') or ( urljoin(self.url, 'api/tickets_api.php') if self.url else '') - # Titles whose create matched a Closed ticket Tinker couldn't reopen: {title: (ticket_id, when)} - self._closed_matches: Dict[str, tuple] = {} def comment(self, ticket_id: str, text: str) -> bool: """Add a Markdown comment to a ticket. Never raises; False means try again later.""" @@ -593,26 +591,21 @@ class TicketClient: logger.error(f'Reading open tickets failed: {e}') return None - # How long to wait before asking again after a create matched an unreopenable Closed ticket. - # Each ask adds a "recurred" comment to that ticket, so once a poll would pile them up. - CLOSED_MATCH_RETRY_S = 24 * 3600 - def create(self, title: str, description: str, priority: str = '2', dedup_key: Optional[str] = None) -> Optional[str]: """Open a ticket. Returns its ID, or None if there is no ticket to track. Tinker deduplicates, on dedup_key when one is sent (tinker_tickets#123), else on the title: the response's `action` says what happened (new, deduplicated, updated, - reopened, new_recurrence, recurrence_noted). recurrence_noted means it matched a Closed - ticket it could not reopen unattended; that ticket isn't tracking this alert, so it - isn't used. + reopened, new_recurrence, recurrence_noted). Every one names the ticket that now tracks + this problem, so Gandalf uses it, as Thor and hwmonDaemon do (gandalf#66 item 6): + reopened is a ticket closed under 7 days ago, new_recurrence a new ticket linked to an + older one, and recurrence_noted a Closed ticket in a workflow set never to reopen + (Tinker adds one note per closed period, so asking again adds nothing). """ if not self.api_key or not self.url: logger.warning('Ticket API not configured: skipping ticket creation') return None - seen = self._closed_matches.get(title) - if seen and time.time() - seen[1] < self.CLOSED_MATCH_RETRY_S: - return None payload = { 'title': title, 'description': description, @@ -639,14 +632,10 @@ class TicketClient: return None action = data.get('action') or 'created' if action == 'recurrence_noted': - self._closed_matches[title] = (tid, time.time()) - logger.warning( - f'Ticket API matched Closed ticket #{tid}, which it could not reopen; not using it ' - f'for this alert. Reopen #{tid} in Tinker to track it there. Retrying in 24 h: {title}' - ) - return None - self._closed_matches.pop(title, None) - logger.info(f'Ticket #{tid} ({action}): {title}') + logger.warning(f'Ticket #{tid} is Closed and Tinker is set never to reopen it; it noted the ' + f'recurrence and Gandalf tracks it there. Reopen it in Tinker to work it: {title}') + else: + logger.info(f'Ticket #{tid} ({action}): {title}') return tid if data.get('existing_ticket_id'): logger.info(f'Duplicate suppressed by API: existing #{data["existing_ticket_id"]}') diff --git a/tests/test_monitor.py b/tests/test_monitor.py index 24cc995..cb2cf39 100644 --- a/tests/test_monitor.py +++ b/tests/test_monitor.py @@ -1204,23 +1204,20 @@ class TestTicketClientCreate: with self._post({'success': True, 'ticket_id': '6'}): assert c.create('u', 'd') == '6' - def test_recurrence_on_a_closed_ticket_is_not_used_and_not_retried_each_poll(self): + def test_every_tinker_action_names_the_ticket_to_track(self): + """gandalf#66 item 6: like Thor and hwmonDaemon, use whatever ticket Tinker names.""" + c = self._client() + for action in ('reopened', 'new_recurrence', 'recurrence_noted', 'updated'): + with self._post({'success': True, 'ticket_id': '993', 'action': action}): + assert c.create('t', 'd') == '993', action + + def test_recurrence_noted_is_not_throttled(self): + # Tinker adds one note per closed period itself, so asking again each poll adds nothing c = self._client() with self._post({'success': True, 'ticket_id': '993', 'action': 'recurrence_noted'}) as post: - assert c.create('t', 'd') is None - assert c.create('t', 'd') is None - assert post.call_count == 1 # the second poll doesn't add another comment to the closed ticket - with self._post({'success': True, 'ticket_id': '7', 'action': 'none'}) as post: - assert c.create('other', 'd') == '7' # other alerts are unaffected - - def test_retry_after_a_day(self): - c = self._client() - with self._post({'success': True, 'ticket_id': '993', 'action': 'recurrence_noted'}): c.create('t', 'd') - c._closed_matches['t'] = ('993', time.time() - c.CLOSED_MATCH_RETRY_S - 1) - with self._post({'success': True, 'ticket_id': '8', 'action': 'none'}): - assert c.create('t', 'd') == '8' - assert 't' not in c._closed_matches + c.create('t', 'd') + assert post.call_count == 2 class TestTicketClientOpenTickets: