  File:
    type: object
    properties:
      filetype:
        type: string
      filename:
        type: string

  LogTarget:
    type: object
    properties:
      id:
        type: integer
      name:
        type: string
      severity:
        type: string
      output:
        type: string

  LogTail:
    type: object
    required:
      - logTargetOutput
      - appId
      - appType
      - appName
      - contents
    properties:
      logTargetOutput:
        type: string
      machine:
        $ref: '#/definitions/AppMachine'
      appId:
        type: integer
      appType:
        type: string
      appName:
        type: string
      contents:
        type: array
        items:
          type: string
      error:
        type: string

  NewMachineReq:
    type: object
    required:
      - address
      - agentCSR
      - agentToken
    properties:
      address:
        type: string
      agentPort:
        type: integer
      agentCSR:
        type: string
        description: Agent Certificate Signing Request.
      serverToken:
        type: string
        description: >-
          A token that is issued by the Stork server. It can be taken
          from Machines page. If it is provided then an agent will
          be immediately authorized in the server and will be operational.
          It may be empty.
      agentToken:
        type: string
        description: >-
          A token that is generated by an agent. An agent traces it in
          the logs during startup and stores it in
          /var/lib/stork-agent/tokens/agent-token.txt. A machine added
          this way to the Stork server requires separate authorization
          that can be made in the Stork server UI or using server API.
          It cannot be empty.
      caCertFingerprint:
        type: string
        description: The SHA256 of the CA certificate stored by the agent in
          hex format without delimiters.
          The server will generate new certificates if an agent has out-of-date
          CA. It is optional to preserve backward compatibility.

  NewMachineResp:
    type: object
    properties:
      id:
        type: integer
        description: The machine ID.
      serverCACert:
        type: string
        description: Server's CA certificate.
      agentCert:
        type: string
        description: Signed agent's certificate.
      serverCertFingerprint:
        type: string
        description: The SHA256 sum of the server GRPC certificate. It's a hex
          representation without delimiters. Agent won't accept the connection
          secured by a different certificate.

  Machine:
    type: object
    required:
      - address
    properties:
      id:
        type: integer
      address:
        type: string
      agentPort:
        type: integer
      authorized:
        type: boolean
      agentToken:
        type: string
      agentVersion:
        type: string
      hostname:
        type: string
      cpus:
        type: integer
      cpusLoad:
        type: string
      memory:
        type: integer
      usedMemory:
        type: integer
      uptime:
        type: integer
      os:
        type: string
      platform:
        type: string
      platformFamily:
        type: string
      platformVersion:
        type: string
      kernelVersion:
        type: string
      kernelArch:
        type: string
      virtualizationSystem:
        type: string
      virtualizationRole:
        type: string
      hostID:
        type: string
      agentUsesHttpCredentials:
        type: boolean
      lastVisitedAt:
        type: string
        format: date-time
        x-nullable: true
      error:
        type: string
      apps:
        type: array
        items:
          $ref: '#/definitions/App'

  Machines:
    type: object
    properties:
      items:
        type: array
        items:
          $ref: '#/definitions/Machine'
      total:
        type: integer

  AppAccessPoint:
     type: object
     properties:
       type:
         type: string
       address:
         type: string
       port:
         type: integer
       useSecureProtocol:
         type: boolean

  AppBase:
    type: object
    properties:
      id:
        type: integer
      name:
        type: string
      type:
        type: string
      accessPoints:
        type: array
        items:
          $ref: '#/definitions/AppAccessPoint'
      version:
        type: string
      machine:
        $ref: '#/definitions/AppMachine'

  App:
    type: object
    properties:
      id:
        type: integer
      name:
        type: string
      type:
        type: string
      accessPoints:
        type: array
        items:
          $ref: '#/definitions/AppAccessPoint'
      version:
        type: string
      machine:
        $ref: '#/definitions/AppMachine'
      details:
        allOf:
          - $ref: '#/definitions/AppKea'
          - $ref: '#/definitions/AppBind9'

  KeaDaemonDatabase:
    type: object
    properties:
      backendType:
        type: string
      database:
        type: string
      host:
        type: string
      dataTypes:
        type: array
        items:
          type: string

  KeaDaemon:
    type: object
    properties:
      id:
        type: integer
      pid:
        type: integer
      name:
        type: string
      active:
        type: boolean
      monitored:
        type: boolean
      version:
        type: string
      extendedVersion:
        type: string
      uptime:
        type: integer
      reloadedAt:
        type: string
        format: date-time
        x-nullable: true
      hooks:
        type: array
        items:
          type: string
      files:
        type: array
        items:
          $ref: '#/definitions/File'
      backends:
        type: array
        items:
          $ref: '#/definitions/KeaDaemonDatabase'
      agentCommErrors:
        type: integer
      caCommErrors:
        type: integer
      daemonCommErrors:
        type: integer
      logTargets:
        type: array
        items:
          $ref: '#/definitions/LogTarget'
      app:
        $ref: '#/definitions/AppBase'

  KeaDaemonConfig:
    type: object
    properties:
      daemonId:
        type: integer
      daemonName:
        type: string
      daemonVersion:
        type: string
      appId:
        type: integer
      appName:
        type: string
      appType:
        type: string
      editable:
        type: boolean
      config:
        type: object
        additionalProperties: true
      options:
        $ref: '#/definitions/DHCPOptions'

  AppKea:
    type: object
    properties:
      extendedVersion:
        type: string
      daemons:
        type: array
        items:
          $ref: '#/definitions/KeaDaemon'

  Bind9Daemon:
    type: object
    properties:
      id:
        type: integer
      pid:
        type: integer
      name:
        type: string
      active:
        type: boolean
      monitored:
        type: boolean
      version:
        type: string
      uptime:
        type: integer
      reloadedAt:
        type: string
        format: date-time
        x-nullable: true
      zoneCount:
        type: integer
      autoZoneCount:
        type: integer
      queryHitRatio:
        type: number
      queryHits:
        type: integer
        x-omitempty: false
      queryMisses:
        type: integer
        x-omitempty: false
      agentCommErrors:
        type: integer
      rndcCommErrors:
        type: integer
      statsCommErrors:
        type: integer

  AppBind9:
    type: object
    properties:
      daemon:
        $ref: '#/definitions/Bind9Daemon'

  AppMachine:
    type: object
    properties:
      id:
        type: integer
      address:
        type: string
      hostname:
        type: string

  Apps:
    type: object
    properties:
      items:
        type: array
        items:
          $ref: '#/definitions/App'
      total:
        type: integer

  AppsStats:
    type: object
    properties:
      keaAppsTotal:
        type: integer
      keaAppsNotOk:
        type: integer
      bind9AppsTotal:
        type: integer
      bind9AppsNotOk:
        type: integer

  KeaHAServerStatus:
    type: object
    properties:
      age:
        type: integer
      appId:
        type: integer
      controlAddress:
        type: string
      failoverTime:
        type: string
        format: date-time
        x-nullable: true
      id:
        type: integer
      inTouch:
        type: boolean
      role:
        type: string
      scopes:
        type: array
        items:
          type: string
      state:
        type: string
      statusTime:
        type: string
        format: date-time
        x-nullable: true
      commInterrupted:
        type: integer
      connectingClients:
        type: integer
      unackedClients:
        type: integer
      unackedClientsLeft:
        type: integer
      analyzedPackets:
        type: integer

  KeaStatus:
    type: object
    properties:
      daemon:
        type: string
      haServers:
        type: object
        properties:
          relationship:
            type: string
          primaryServer:
            $ref: '#/definitions/KeaHAServerStatus'
          secondaryServer:
            $ref: '#/definitions/KeaHAServerStatus'

  ServiceStatus:
    type: object
    properties:
      status:
        allOf:
          - $ref: '#/definitions/KeaStatus'

  ServicesStatus:
    type: object
    properties:
      items:
        type: array
        items:
          $ref: '#/definitions/ServiceStatus'

  ConfigReview:
    type: object
    properties:
      id:
        type: integer
      daemonId:
        type: integer
      createdAt:
        type: string
        format: date-time

  ConfigReport:
    type: object
    properties:
      id:
        type: integer
      createdAt:
        type: string
        format: date-time
      checker:
        type: string
      content:
        type: string
        x-nullable: true

  ConfigReports:
    type: object
    properties:
      review:
        $ref: '#/definitions/ConfigReview'
      items:
        type: array
        items:
          $ref: '#/definitions/ConfigReport'
      total:
        type: integer
      totalIssues:
        type: integer
      totalReports:
        type: integer

  ConfigCheckerState:
    type: string
    enum: &CONFIGCHECKERSTATE
      - "enabled"
      - "disabled"
      - "inherit"

  ConfigChecker:
    type: object
    required:
      - name
      - triggers
      - selectors
      - state
      - globallyEnabled
    properties:
      name:
        type: string
      triggers:
        type: array
        items:
          type: string
      selectors:
        type: array
        items:
          type: string
      state:
        enum: *CONFIGCHECKERSTATE
      globallyEnabled:
        type: boolean
  ConfigCheckers:
    type: object
    properties:
      items:
        type: array
        items:
          $ref: '#/definitions/ConfigChecker'
      total:
        type: integer

  ConfigCheckerPreference:
    type: object
    properties:
      name:
        type: string
      state:
        enum: *CONFIGCHECKERSTATE

  ConfigCheckerPreferences:
    type: object
    properties:
      items:
        type: array
        items:
          $ref: '#/definitions/ConfigCheckerPreference'
      total:
        type: integer