Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Gotify custom service component #706

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/customservices.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ within Homer:
- [Tdarr](#tdarr)
- [PiAlert](#pialert)
- [Immich](#immich)
- [Gotify](#gotify)

If you experiencing any issue, please have a look to the [troubleshooting](troubleshooting.md) page.

Expand Down Expand Up @@ -445,3 +446,16 @@ The Immich service displays stats from your Immich server.
apikey: "<--- Your api key --->" # administrator user
updateInterval: 5000 # (Optional) Interval (in ms) for updating the stats
```

## Gotify

The Gotify service will show the number of currently oustanding messages
available as well as the overall health of the system.

Note that `apikey` must be a client token, not an app token.

```yaml
- name: "Gotify"
type: "Gotify"
apikey: "<api_key>" # Client token to retrieve messages
```
105 changes: 105 additions & 0 deletions src/components/services/Gotify.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<template>
<Generic :item="item">
<template #content>
<p class="title is-4">{{ item.name }}</p>
<p class="subtitle is-6">
<template v-if="messages > 0">
<template v-if="messages > 100">100+</template>
<template v-else>{{ messages }}</template>
<template v-if="messages === 1"> message</template>
<template v-else> messages</template>
</template>
</p>
</template>
<template #indicator>
<div v-if="status" class="status" :class="status"></div>
</template>
</Generic>
</template>

<script>
import service from "@/mixins/service.js";
import Generic from "./Generic.vue";

export default {
name: "Gotify",
mixins: [service],
props: {
item: Object,
},
components: {
Generic,
},
data: () => ({
health: {},
messages: 0,
}),
computed: {
status: function () {
const statuses = [this.health.health, this.health.database];

if (statuses.includes("red")) {
return "red";
} else if (statuses.includes("orange")) {
return "orange";
}

return "green";
}
},
created() {
this.fetchStatus();
this.fetchMessages();
},
methods: {
fetchStatus: async function () {
await this.fetch(`/health`)
.catch((e) => console.log(e))
.then((resp) => this.health = resp);
},
fetchMessages: async function () {
const headers = {
"X-Gotify-Key": this.item.apikey,
};
await this.fetch(`/message?limit=100`, { headers })
.catch((e) => console.log(e))
.then((resp) => this.messages = resp.messages.length);
},
},
};
</script>

<style scoped lang="scss">
.status {
font-size: 0.8rem;
color: var(--text-title);

&.green:before {
background-color: #94e185;
border-color: #78d965;
box-shadow: 0 0 5px 1px #94e185;
}

&.orange:before {
background-color: #ee863e;
border-color: #e77322;
box-shadow: 0 0 5px 1px #ee863e;
}

&.red:before {
background-color: #c9404d;
border-color: #c42c3b;
box-shadow: 0 0 5px 1px #c9404d;
}

&:before {
content: " ";
display: inline-block;
width: 7px;
height: 7px;
margin-right: 10px;
border: 1px solid #000;
border-radius: 7px;
}
}
</style>