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