Skip to content

Commit

Permalink
Merge pull request #44 from vst/37-report-time-related-information
Browse files Browse the repository at this point in the history
Host's Hostname and Timezone
  • Loading branch information
vst authored Mar 31, 2024
2 parents 8f5e2b5 + 2859ac3 commit e036b19
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/Lhp/Remote.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Data.Maybe (catMaybes, fromMaybe)
import qualified Data.Scientific as S
import qualified Data.Text as T
import qualified Lhp.Config as Config
import Lhp.Types (HostReport (_hostReportTimezone))
import qualified Lhp.Types as Types
import System.Exit (ExitCode (..))
import System.IO (hPutStrLn, stderr)
Expand Down Expand Up @@ -65,6 +66,8 @@ compileHostReport
compileHostReport h@Types.Host {..} = do
kvs <- (++) <$> _fetchHostInfo _hostName <*> _fetchHostCloudInfo _hostName
let _hostReportHost = h
_hostReportHostname <- _toParseError _hostName $ _getParse pure "LHP_GENERAL_HOSTNAME" kvs
_hostReportTimezone <- _toParseError _hostName $ _getParse pure "LHP_GENERAL_TIMEZONE" kvs
_hostReportCloud <- _mkCloud _hostName kvs
_hostReportHardware <- _mkHardware _hostName kvs
_hostReportKernel <- _mkKernel _hostName kvs
Expand Down
4 changes: 4 additions & 0 deletions src/Lhp/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ instance ADC.HasCodec Host where
-- | Data definition for host patrol report.
data HostReport = HostReport
{ _hostReportHost :: !Host
, _hostReportHostname :: !T.Text
, _hostReportTimezone :: !T.Text
, _hostReportCloud :: !Cloud
, _hostReportHardware :: !Hardware
, _hostReportKernel :: !Kernel
Expand All @@ -90,6 +92,8 @@ instance ADC.HasCodec HostReport where
ADC.object "Report" $
HostReport
<$> ADC.requiredField "host" "Host descriptor." ADC..= _hostReportHost
<*> ADC.requiredField "hostname" "Hostname of the host." ADC..= _hostReportHostname
<*> ADC.requiredField "timezone" "Timezone of the host." ADC..= _hostReportTimezone
<*> ADC.requiredField "cloud" "Cloud information." ADC..= _hostReportCloud
<*> ADC.requiredField "hardware" "Hardware information." ADC..= _hostReportHardware
<*> ADC.requiredField "kernel" "Kernel information." ADC..= _hostReportKernel
Expand Down
2 changes: 2 additions & 0 deletions src/scripts/info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ _check_file /etc/os-release
# PROCEDURE #
#############

_print_var "LHP_GENERAL_HOSTNAME" "$(hostname)"
_print_var "LHP_GENERAL_TIMEZONE" "$(timedatectl | grep "Time zone" | cut -f 2- -d ":" | xargs)"
_print_var "LHP_HW_CPU" "$(nproc)"
_print_var "LHP_HW_RAM" "$(grep -oP 'MemTotal:\s+\K\d+' /proc/meminfo)"
_print_var "LHP_HW_DISK" "$(df -k --output=size / | tail -n +2 | grep -o '[[:digit:]]*')"
Expand Down
20 changes: 13 additions & 7 deletions website/src/components/report/ShowHostDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { KVBox } from '../helpers';
export function ShowHostDetails({ host }: { host: LhpHostReport }) {
return (
<div className="space-y-4 px-4 py-4">
<h1 className="flex flex-row justify-between text-xl font-bold">
<h1 className="flex flex-row items-center justify-between text-xl font-bold">
<div className="space-x-2">
<span>{host.host.name}</span>
{host.host.url && (
Expand All @@ -19,12 +19,18 @@ export function ShowHostDetails({ host }: { host: LhpHostReport }) {
)}
</div>

<div className="space-x-1">
{(host.host.tags || []).map((x) => (
<Chip key={x} size="sm" color="primary" variant="flat" radius="sm">
{x}
</Chip>
))}
<div className="align-items flex flex-row items-center space-x-4">
<div className="text-xs font-medium text-gray-500">
{host.hostname} on {host.timezone}
</div>

<div className="space-x-1 pb-1">
{(host.host.tags || []).map((x) => (
<Chip key={x} size="sm" color="primary" variant="flat" radius="sm">
{x}
</Chip>
))}
</div>
</div>
</h1>

Expand Down
28 changes: 27 additions & 1 deletion website/src/components/report/TabulateHosts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ export function TabulateHosts({
</Select>
</div>

<div className="rounded-lg bg-gray-100 p-2">
<Select
label="Timezones"
selectionMode="multiple"
variant="underlined"
className="max-w-xs"
onSelectionChange={(x: Selection) => {
setFilters({ ...filters, timezone: x === 'all' || x.size === 0 ? () => true : (h) => x.has(h.timezone) });
}}
>
{hosts
.map((host) => host.timezone)
.sort()
.filter(function (el, i, a) {
return i === a.indexOf(el);
})
.map((t) => (
<SelectItem key={t}>{t}</SelectItem>
))}
</Select>
</div>

<div className="rounded-lg bg-gray-100 p-2">
<Select
label="Clouds"
Expand Down Expand Up @@ -137,7 +159,7 @@ export function TabulateHosts({
</Select>
</div>

<div className="col-span-5 rounded-lg bg-gray-100 p-2">
<div className="col-span-4 rounded-lg bg-gray-100 p-2">
<Select
label="Authorized SSH Keys"
selectionMode="multiple"
Expand Down Expand Up @@ -300,7 +322,9 @@ export function TabulateHosts({
showSelectionCheckboxes={false}
>
<TableHeader>
<TableColumn key="name">Name</TableColumn>
<TableColumn key="hostname">Hostname</TableColumn>
<TableColumn key="timezone">Timezone</TableColumn>
<TableColumn key="cloud">Cloud</TableColumn>
<TableColumn key="distro">Distribution</TableColumn>
<TableColumn key="arch">Arch</TableColumn>
Expand Down Expand Up @@ -353,6 +377,8 @@ export function TabulateHosts({
)}
</div>
</TableCell>
<TableCell>{host.hostname}</TableCell>
<TableCell>{host.timezone.split(' ', 1)[0] || 'UNKNOWN'}</TableCell>
<TableCell>
{host.cloud.name}
{host.cloud.hostRegion && <span className="text-xs text-gray-400"> {host.cloud.hostRegion}</span>}
Expand Down
4 changes: 4 additions & 0 deletions website/src/lib/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export const LHP_PATROL_REPORT_SCHEMA = {
required: ['name'],
type: 'object',
},
hostname: { $comment: 'Hostname of the host.', type: 'string' },
kernel: {
$comment: 'Kernel information.\nKernel Information\nKernel',
properties: {
Expand All @@ -167,6 +168,7 @@ export const LHP_PATROL_REPORT_SCHEMA = {
items: { type: 'string' },
type: 'array',
},
timezone: { $comment: 'Timezone of the host.', type: 'string' },
},
required: [
'systemdTimers',
Expand All @@ -177,6 +179,8 @@ export const LHP_PATROL_REPORT_SCHEMA = {
'kernel',
'hardware',
'cloud',
'timezone',
'hostname',
'host',
],
type: 'object',
Expand Down

0 comments on commit e036b19

Please sign in to comment.