Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

3.7 KB
Raw Blame
export type CanonicalFrontendResourceType =
  | 'agent'
  | 'ceph'
  | 'vm'
  | 'system-container'
  | 'app-container'
  | 'oci-container'
  | 'pod'
  | 'storage'
  | 'disk'
  | 'docker-host'
  | 'docker-image'
  | 'docker-volume'
  | 'docker-network'
  | 'docker-task'
  | 'docker-swarm-node'
  | 'docker-secret'
  | 'docker-config'
  | 'network'
  | 'network-share'
  | 'pbs'
  | 'pmg'
  | 'k8s-node'
  | 'k8s-cluster'
  | 'k8s-deployment'
  | 'k8s-replicaset'
  | 'k8s-service'
  | 'k8s-namespace'
  | 'k8s-statefulset'
  | 'k8s-daemonset'
  | 'k8s-job'
  | 'k8s-cronjob'
  | 'k8s-ingress'
  | 'k8s-endpoint-slice'
  | 'k8s-network-policy'
  | 'k8s-persistent-volume'
  | 'k8s-persistent-volume-claim'
  | 'k8s-storage-class'
  | 'k8s-configmap'
  | 'k8s-secret'
  | 'k8s-serviceaccount'
  | 'k8s-resource-quota'
  | 'k8s-limit-range'
  | 'k8s-pod-disruption-budget'
  | 'k8s-horizontal-pod-autoscaler'
  | 'k8s-event'
  | 'network-endpoint';

const asNormalizedString = (value: unknown): string | undefined => {
  if (typeof value !== 'string') return undefined;
  const trimmed = value.trim().toLowerCase();
  return trimmed.length > 0 ? trimmed : undefined;
};

export const canonicalizeFrontendResourceType = (
  value: unknown,
): CanonicalFrontendResourceType | undefined => {
  const normalized = asNormalizedString(value);
  if (!normalized) return undefined;

  switch (normalized) {
    case 'host':
    case 'hosts':
    case 'truenas':
      return 'agent';
    case 'availability':
    case 'endpoint':
    case 'network_endpoint':
      return 'network-endpoint';
    case 'docker':
      return 'app-container';
    case 'dockerhost':
    case 'docker_host':
      return 'docker-host';
    case 'docker-node':
    case 'docker_node':
    case 'docker-nodes':
    case 'docker_nodes':
    case 'swarm-node':
    case 'swarm_node':
    case 'swarm-nodes':
    case 'swarm_nodes':
      return 'docker-swarm-node';
    case 'swarm-secret':
    case 'swarm_secret':
    case 'swarm-secrets':
    case 'swarm_secrets':
      return 'docker-secret';
    case 'swarm-config':
    case 'swarm_config':
    case 'swarm-configs':
    case 'swarm_configs':
      return 'docker-config';
    case 'k8s':
    case 'kubernetes':
    case 'k8s-pod':
      return 'pod';
    case 'kubernetes-cluster':
    case 'kubernetes_cluster':
      return 'k8s-cluster';
    case 'kubernetes-node':
    case 'kubernetes_node':
      return 'k8s-node';
    case 'agent':
    case 'ceph':
    case 'vm':
    case 'system-container':
    case 'app-container':
    case 'oci-container':
    case 'pod':
      return normalized;
    case 'node':
      return 'agent';
    case 'storage':
    case 'disk':
    case 'docker-host':
    case 'docker-image':
    case 'docker-volume':
    case 'docker-network':
    case 'docker-task':
    case 'docker-swarm-node':
    case 'docker-secret':
    case 'docker-config':
    case 'network':
    case 'network-share':
    case 'pbs':
    case 'pmg':
    case 'k8s-node':
    case 'k8s-cluster':
    case 'k8s-deployment':
    case 'k8s-replicaset':
    case 'k8s-service':
    case 'k8s-namespace':
    case 'k8s-statefulset':
    case 'k8s-daemonset':
    case 'k8s-job':
    case 'k8s-cronjob':
    case 'k8s-ingress':
    case 'k8s-endpoint-slice':
    case 'k8s-network-policy':
    case 'k8s-persistent-volume':
    case 'k8s-persistent-volume-claim':
    case 'k8s-storage-class':
    case 'k8s-configmap':
    case 'k8s-secret':
    case 'k8s-serviceaccount':
    case 'k8s-resource-quota':
    case 'k8s-limit-range':
    case 'k8s-pod-disruption-budget':
    case 'k8s-horizontal-pod-autoscaler':
    case 'k8s-event':
    case 'network-endpoint':
      return normalized;
    default:
      return undefined;
  }
};