@@ -4,6 +4,7 @@ import { StringDecoder } from 'node:string_decoder';
44import axios , { type AxiosRequestConfig } from 'axios' ;
55import type { Logger } from 'pino' ;
66import type {
7+ ContainerUpdateAppliedEventPayload ,
78 ContainerUpdateFailedEventPayload ,
89 SecurityAlertEventPayload ,
910 SecurityAlertSummary ,
@@ -51,9 +52,12 @@ interface AgentClientRuntimeInfo {
5152}
5253
5354interface AgentComponentDescriptor {
55+ id ?: string ;
5456 type : string ;
5557 name : string ;
5658 configuration : Record < string , unknown > ;
59+ agent ?: string ;
60+ metadata ?: Record < string , unknown > ;
5761}
5862
5963interface AgentRuntimeAckPayload {
@@ -90,6 +94,17 @@ const INITIAL_SSE_RECONNECT_DELAY_MS = 1_000;
9094const MAX_SSE_RECONNECT_DELAY_MS = 60_000 ;
9195const REMOTE_UPDATE_TRIGGER_TYPES = new Set ( [ 'docker' , 'dockercompose' ] ) ;
9296
97+ function isContainerUpdateAppliedEventPayload (
98+ data : unknown ,
99+ ) : data is ContainerUpdateAppliedEventPayload {
100+ if ( ! data || typeof data !== 'object' ) {
101+ return false ;
102+ }
103+
104+ const containerName = ( data as { containerName ?: unknown } ) . containerName ;
105+ return typeof containerName === 'string' && containerName . length > 0 ;
106+ }
107+
93108export class AgentClient {
94109 public name : string ;
95110 public config : AgentClientConfig ;
@@ -604,6 +619,17 @@ export class AgentClient {
604619 case 'dd:update-applied' :
605620 if ( typeof data === 'string' && data . length > 0 ) {
606621 await emitContainerUpdateApplied ( data ) ;
622+ } else if ( isContainerUpdateAppliedEventPayload ( data ) ) {
623+ await emitContainerUpdateApplied ( {
624+ containerName : data . containerName ,
625+ container :
626+ data . container && typeof data . container === 'object'
627+ ? {
628+ ...data . container ,
629+ agent : this . name ,
630+ }
631+ : undefined ,
632+ } ) ;
607633 }
608634 return ;
609635 case 'dd:update-failed' : {
@@ -742,6 +768,21 @@ export class AgentClient {
742768 }
743769 }
744770
771+ async getWatcher ( watcherType : string , watcherName : string ) {
772+ try {
773+ const response = await axios . get < AgentComponentDescriptor > (
774+ `${ this . baseUrl } /api/watchers/${ encodeURIComponent ( watcherType ) } /${ encodeURIComponent ( watcherName ) } ` ,
775+ this . axiosOptions ,
776+ ) ;
777+ return response . data ;
778+ } catch ( error : unknown ) {
779+ this . log . error (
780+ `Error fetching watcher on agent: ${ sanitizeLogParam ( getErrorMessage ( error ) ) } ` ,
781+ ) ;
782+ throw error ;
783+ }
784+ }
785+
745786 async watch ( watcherType : string , watcherName : string ) {
746787 try {
747788 const response = await axios . post < ContainerReport [ ] > (
0 commit comments