Close the osTicket ticket along with an alert

The Close drawer can also close the alert's osTicket ticket. osTicket's API
cannot, so this writes to its database with a separate, optional login: the
ticket is set to Closed, a note in its thread says who closed it and why, and
the closed event is recorded, in one transaction. Tables and columns are
checked first, only an open ticket is closed, and a ticket closed by somebody
else at the same moment is left alone. Summary tickets are not closed from here.

"Test closing" (Alert tickets settings) tries every write and rolls it back.
If the ticket cannot be closed the alert is still closed and the reason is
said, noted on the incident and audited.

Not run against a real osTicket: tested against a pretend database only.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-25 21:27:38 +01:00
1 parent a94899865e
commit 5ae61a1ece
21 files changed
+8405 -23

No files matched your search

+29 -2
View File
@@ -219,8 +219,8 @@ That works on every Duplicati version, needs no login handshake and leaves nothi
- **What is sent:** one ticket per problem — name and email you set under Settings → Notifications → Alert tickets, a subject, the
problem's text and a link back to this app, optionally a help topic and priority id — with `autorespond` off (the
"user" is this app, so an acknowledgement would only bounce) and osTicket's own staff alert on or off as you choose.
- **What it can't do:** close, reopen, or comment on a ticket — osTicket's API has no such endpoint. A ticket opened
here is yours to close in osTicket.
- **What the API can't do:** close, reopen, or comment on a ticket — osTicket's API has no such endpoint. Closing one is
a separate, optional thing, described next, and it does not use the API.
- **Checked against a real osTicket for a test ticket** (the API key with its IP restriction, creating the ticket, and the
message arriving exactly as written, line breaks and non-ASCII characters included). It was built from osTicket's
published API documentation and tested against a stand-in server too, and the real one showed two mistakes the stand-in
@@ -229,6 +229,33 @@ That works on every Duplicati version, needs no login handshake and leaves nothi
A ticket opened for a real alert has been seen working too; a summary ticket (many problems at once) has not been seen on a real osTicket yet. If osTicket rejects a ticket, "Send a test
ticket" shows the reason it gave.
**Optional: closing the ticket when you close the alert** (the *Also close the osTicket ticket* tick box in the Close drawer on the Alerts page)
osTicket's API cannot close a ticket, so this is the one place in the app that **writes to another application's database**. Read the next paragraphs before switching it on.
- **Config fields:** Database username for closing tickets (optional) and its password (optional, stored encrypted). They are **separate from the read-only login above**, on purpose: closing is granted to one account and never widens what reading may do.
Leave them empty and nothing here ever runs.
- **Make the login in MySQL/MariaDB**, with only what closing needs (replace `osticket` and the prefix if yours differ):
```sql
CREATE USER 'homelab_close'@'%' IDENTIFIED BY 'a-strong-password';
GRANT SELECT ON osticket.ost_ticket_status TO 'homelab_close'@'%';
GRANT SELECT ON osticket.ost_thread TO 'homelab_close'@'%';
GRANT SELECT ON osticket.ost_event TO 'homelab_close'@'%';
GRANT SELECT, UPDATE (status_id, closed, lastupdate, updated, isanswered, isoverdue) ON osticket.ost_ticket TO 'homelab_close'@'%';
GRANT INSERT ON osticket.ost_thread_entry TO 'homelab_close'@'%';
GRANT INSERT ON osticket.ost_thread_event TO 'homelab_close'@'%';
FLUSH PRIVILEGES;
```
- **What a close writes** — what osTicket's own *Close* does, in **one transaction** (all or none): the ticket's status becomes a closed one (the one called *Closed*, else the first closed status), its *closed* and *last update* times are set and it is no longer marked answered or overdue; a **note** in the ticket's thread says
*Closed from Homelab Manager by <name>* with the reason you gave; and a **"closed" event** is recorded so the ticket's history reads like any other. Nothing else is touched, and nothing is ever deleted.
- **What it checks first:** that the tables and columns it writes to are there (written for **osTicket 1.14–1.18**); a different osTicket is refused with the list of what is missing, before anything is written. It closes only a ticket that is **open**, and only if its status is still what it was when it was read — a ticket somebody
else closes at the same moment is left as they left it. A ticket that was opened as part of a **summary ticket** (many problems at once) is not closed from here, because it covers other alerts.
- **Test closing** (Settings → Notifications → Alert tickets, next to *Send a test ticket*; administrators): signs in with the login, checks the tables and columns, and then **tries every write a close makes inside a transaction that is rolled back** — so a missing grant is found there and not on the first real ticket. Nothing stays (a counter or two
inside the database moves on).
- **What the alert shows:** the ticket badge says *(closed)* once it has been closed from here, and the Close drawer says so instead of offering it again. If the ticket cannot be closed, the alert is **still closed** and you are told why; the reason is also written on the incident and in the audit log (`alert_ticket/close_ticket`, `close_ticket_failed`).
- **Not verified against a live osTicket — and this is the least verified part of the app.** There was no MySQL/MariaDB server to run it on; it is built from osTicket's published schema and tried only against a pretend database that answers the exact statements it sends. For opening tickets, a real osTicket showed two mistakes that a
stand-in server had hidden, and the same can happen here (a column that is called something else in your version, a status or event that is set up differently). That is what *Test closing* is for: **run it first**, and try the first real close on a ticket that does not matter. If something is wrong the error says what; tell me and I'll adjust.
### phpIPAM
- **Config fields:** phpIPAM URL, API app ID, App token