outposts: include hostname in outpost heartbeat
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
a148e611f3
commit
2b2323fae7
|
@ -19,7 +19,13 @@ from authentik.core.api.utils import PassiveSerializer, is_dict
|
|||
from authentik.core.models import Provider
|
||||
from authentik.outposts.api.service_connections import ServiceConnectionSerializer
|
||||
from authentik.outposts.apps import MANAGED_OUTPOST
|
||||
from authentik.outposts.models import Outpost, OutpostConfig, OutpostType, default_outpost_config
|
||||
from authentik.outposts.models import (
|
||||
Outpost,
|
||||
OutpostConfig,
|
||||
OutpostState,
|
||||
OutpostType,
|
||||
default_outpost_config,
|
||||
)
|
||||
from authentik.providers.ldap.models import LDAPProvider
|
||||
from authentik.providers.proxy.models import ProxyProvider
|
||||
|
||||
|
@ -96,6 +102,7 @@ class OutpostDefaultConfigSerializer(PassiveSerializer):
|
|||
class OutpostHealthSerializer(PassiveSerializer):
|
||||
"""Outpost health status"""
|
||||
|
||||
uid = CharField(read_only=True)
|
||||
last_seen = DateTimeField(read_only=True)
|
||||
version = CharField(read_only=True)
|
||||
version_should = CharField(read_only=True)
|
||||
|
@ -105,6 +112,8 @@ class OutpostHealthSerializer(PassiveSerializer):
|
|||
build_hash = CharField(read_only=True, required=False)
|
||||
build_hash_should = CharField(read_only=True, required=False)
|
||||
|
||||
hostname = CharField(read_only=True, required=False)
|
||||
|
||||
|
||||
class OutpostFilter(FilterSet):
|
||||
"""Filter for Outposts"""
|
||||
|
@ -145,13 +154,16 @@ class OutpostViewSet(UsedByMixin, ModelViewSet):
|
|||
outpost: Outpost = self.get_object()
|
||||
states = []
|
||||
for state in outpost.state:
|
||||
state: OutpostState
|
||||
states.append(
|
||||
{
|
||||
"uid": state.uid,
|
||||
"last_seen": state.last_seen,
|
||||
"version": state.version,
|
||||
"version_should": state.version_should,
|
||||
"version_outdated": state.version_outdated,
|
||||
"build_hash": state.build_hash,
|
||||
"hostname": state.hostname,
|
||||
"build_hash_should": get_build_hash(),
|
||||
}
|
||||
)
|
||||
|
|
|
@ -98,6 +98,7 @@ class OutpostConsumer(AuthJsonConsumer):
|
|||
if self.channel_name not in state.channel_ids:
|
||||
state.channel_ids.append(self.channel_name)
|
||||
state.last_seen = datetime.now()
|
||||
state.hostname = msg.args.get("hostname", "")
|
||||
|
||||
if not self.first_msg:
|
||||
GAUGE_OUTPOSTS_CONNECTED.labels(
|
||||
|
|
|
@ -431,6 +431,7 @@ class OutpostState:
|
|||
version: Optional[str] = field(default=None)
|
||||
version_should: Version | LegacyVersion = field(default=OUR_VERSION)
|
||||
build_hash: str = field(default="")
|
||||
hostname: str = field(default="")
|
||||
|
||||
_outpost: Optional[Outpost] = field(default=None)
|
||||
|
||||
|
|
|
@ -167,6 +167,19 @@ func (a *APIController) OnRefresh() error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (a *APIController) getWebsocketArgs() map[string]interface{} {
|
||||
args := map[string]interface{}{
|
||||
"version": constants.VERSION,
|
||||
"buildHash": constants.BUILD("tagged"),
|
||||
"uuid": a.instanceUUID.String(),
|
||||
}
|
||||
hostname, err := os.Hostname()
|
||||
if err == nil {
|
||||
args["hostname"] = hostname
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
func (a *APIController) StartBackgroundTasks() error {
|
||||
OutpostInfo.With(prometheus.Labels{
|
||||
"outpost_name": a.Outpost.Name,
|
||||
|
|
|
@ -49,11 +49,7 @@ func (ac *APIController) initWS(akURL url.URL, outpostUUID string) error {
|
|||
// Send hello message with our version
|
||||
msg := websocketMessage{
|
||||
Instruction: WebsocketInstructionHello,
|
||||
Args: map[string]interface{}{
|
||||
"version": constants.VERSION,
|
||||
"buildHash": constants.BUILD("tagged"),
|
||||
"uuid": ac.instanceUUID.String(),
|
||||
},
|
||||
Args: ac.getWebsocketArgs(),
|
||||
}
|
||||
err = ws.WriteJSON(msg)
|
||||
if err != nil {
|
||||
|
@ -163,11 +159,7 @@ func (ac *APIController) startWSHealth() {
|
|||
for ; true; <-ticker.C {
|
||||
aliveMsg := websocketMessage{
|
||||
Instruction: WebsocketInstructionHello,
|
||||
Args: map[string]interface{}{
|
||||
"version": constants.VERSION,
|
||||
"buildHash": constants.BUILD("tagged"),
|
||||
"uuid": ac.instanceUUID.String(),
|
||||
},
|
||||
Args: ac.getWebsocketArgs(),
|
||||
}
|
||||
if ac.wsConn == nil {
|
||||
go ac.reconnectWS()
|
||||
|
|
|
@ -30179,6 +30179,9 @@ components:
|
|||
type: object
|
||||
description: Outpost health status
|
||||
properties:
|
||||
uid:
|
||||
type: string
|
||||
readOnly: true
|
||||
last_seen:
|
||||
type: string
|
||||
format: date-time
|
||||
|
@ -30198,10 +30201,15 @@ components:
|
|||
build_hash_should:
|
||||
type: string
|
||||
readOnly: true
|
||||
hostname:
|
||||
type: string
|
||||
readOnly: true
|
||||
required:
|
||||
- build_hash
|
||||
- build_hash_should
|
||||
- hostname
|
||||
- last_seen
|
||||
- uid
|
||||
- version
|
||||
- version_outdated
|
||||
- version_should
|
||||
|
|
Reference in a new issue