Add Location handling
This commit is contained in:
parent
26f9ac2099
commit
795609f0a0
4 changed files with 48 additions and 75 deletions
|
@ -1,7 +1,9 @@
|
|||
import { ServiceLocation } from './CardTypes';
|
||||
export interface DockerInfo {
|
||||
name: string,
|
||||
status: DockerStatus,
|
||||
id: string
|
||||
location: ServiceLocation,
|
||||
}
|
||||
|
||||
export enum DockerStatus {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import Docker from 'dockerode'
|
||||
import ApiSecret from '../../private/portainer_api_secret.json'
|
||||
import { DockerInfo } from '../../interfaces/DockerStatus';
|
||||
import { ServiceLocation } from '../../interfaces/CardTypes';
|
||||
|
||||
export default async function ContainersAPI(req: any, res: any) {
|
||||
const token = JSON.parse(JSON.stringify(ApiSecret.token));
|
||||
|
@ -20,6 +21,7 @@ export default async function ContainersAPI(req: any, res: any) {
|
|||
newEntry.name = entry.Names[0].substring(1);
|
||||
newEntry.status = entry.State;
|
||||
newEntry.id = entry.Id;
|
||||
newEntry.location = ServiceLocation.tower_0;
|
||||
list.push(newEntry);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import Head from 'next/head'
|
||||
import { Game } from '../interfaces/CardTypes';
|
||||
import { PageContentBox, PageDescription, PageTitle, CardContentGame } from '../components/styles/content'
|
||||
import GameList from '../public/pages.json';
|
||||
import GameList from '../public/data/pages.json';
|
||||
|
||||
function Servers() {
|
||||
// TODO: unuggly this shit
|
||||
|
|
|
@ -61,8 +61,6 @@ async function getStatus(entry: Service, containers: DockerInfo[]) {
|
|||
// Currently the only location supporting different fetching depending on type is brr7-4800u
|
||||
// Others to follow but low prio as this is currently the only location used
|
||||
|
||||
// Location BRR7-4800U
|
||||
if (entry.location === ServiceLocation.brr7_4800u) {
|
||||
// Type APP
|
||||
if (entry.type === ServiceType.app) {
|
||||
await fetch(entry.href)
|
||||
|
@ -95,6 +93,8 @@ async function getStatus(entry: Service, containers: DockerInfo[]) {
|
|||
const container = containers[i];
|
||||
// Docker API returns container names with / prepended
|
||||
if (container.name === entry.docker_container_name) {
|
||||
|
||||
if (container.location === entry.location) {
|
||||
// so far only "running" is properly implemented, mroe cases to follow as needed
|
||||
switch (container.status) {
|
||||
case "running":
|
||||
|
@ -108,6 +108,7 @@ async function getStatus(entry: Service, containers: DockerInfo[]) {
|
|||
// cancel the for
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If container name is not missing the container is set to offline
|
||||
else {
|
||||
entry.status = Status.offline;
|
||||
|
@ -128,38 +129,6 @@ async function getStatus(entry: Service, containers: DockerInfo[]) {
|
|||
console.warn("Service Type for Service " + entry.name + " not specified or invalid");
|
||||
entry.status = Status.error;
|
||||
}
|
||||
}
|
||||
// Location Other
|
||||
// TODO: implement docker type for other locations
|
||||
else if (entry.location === ServiceLocation.other) {
|
||||
// Currently uses the same handling as app type for the other location
|
||||
await fetch(entry.href)
|
||||
.then((response) => {
|
||||
if (response.ok) {
|
||||
switch (response.status) {
|
||||
case 200:
|
||||
case 301:
|
||||
case 302:
|
||||
entry.status = Status.online;
|
||||
break;
|
||||
default:
|
||||
entry.status = Status.offline;
|
||||
}
|
||||
}
|
||||
else {
|
||||
entry.status = Status.offline;
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error pinging Website: ", error);
|
||||
entry.status = Status.error;
|
||||
})
|
||||
}
|
||||
// If no Location matches
|
||||
else {
|
||||
console.warn("Service Location for Service " + entry.name + " not specified");
|
||||
entry.status = Status.error;
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue