Skip to content

Commit

Permalink
bug fix and improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
mehatab committed Jun 18, 2023
1 parent 2893cb5 commit 9214f40
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 74 deletions.
16 changes: 12 additions & 4 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import '../styles/globals.css'
import type { AppProps } from 'next/app'
import "../styles/globals.css";
import type { AppProps } from "next/app";
import Head from "next/head";

function MyApp({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
return (
<>
<Head>
<title>System Status</title>
</Head>
<Component {...pageProps} />
</>
);
}

export default MyApp
export default MyApp;
44 changes: 24 additions & 20 deletions scripts/health-check.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
#!/bin/bash

commit=true
origin=$(git remote get-url origin)
if [[ $origin == *statsig-io/statuspage* ]]
then
commit=false
fi

KEYSARRAY=()
URLSARRAY=()
declare -a KEYSARRAY
declare -a URLSARRAY

urlsConfig="public/urls.cfg"
echo "Reading $urlsConfig"
while read -r line
while IFS='=' read -r key url
do
echo " $line"
IFS='=' read -ra TOKENS <<< "$line"
KEYSARRAY+=(${TOKENS[0]})
URLSARRAY+=(${TOKENS[1]})
echo " $key=$url"
KEYSARRAY+=("$key")
URLSARRAY+=("$url")
done < "$urlsConfig"

echo "***********************"
echo "Starting health checks with ${#KEYSARRAY[@]} configs:"

mkdir -p logs

for (( index=0; index < ${#KEYSARRAY[@]}; index++))
for (( index=0; index < ${#KEYSARRAY[@]}; index++ ))
do
key="${KEYSARRAY[index]}"
url="${URLSARRAY[index]}"
echo " $key=$url"

for i in 1 2 3;
for i in {1..3}
do
response=$(curl -o /dev/null -s -w '%{http_code} %{time_total}' --silent --output /dev/null $url)
http_code=$(echo $response | cut -d ' ' -f 1)
time_total=$(echo $response | cut -d ' ' -f 2)
response=$(curl -o /dev/null -s -w '%{http_code} %{time_total}' --silent --output /dev/null "$url")
http_code=$(echo "$response" | cut -d ' ' -f 1)
time_total=$(echo "$response" | cut -d ' ' -f 2)
echo " $http_code $time_total"
if [ "$http_code" -eq 200 ] || [ "$http_code" -eq 202 ] || [ "$http_code" -eq 301 ] || [ "$http_code" -eq 302 ] || [ "$http_code" -eq 307 ]; then
result="success"
Expand All @@ -48,18 +49,21 @@ do
dateTime=$(date +'%Y-%m-%d %H:%M')
if [[ $commit == true ]]
then
echo $dateTime, $result, $time_total >> "public/status/${key}_report.log"
echo "$(tail -2000 public/status/${key}_report.log)" > "public/status/${key}_report.log"
mkdir -p public/status
echo "$dateTime, $result, $time_total" >> "public/status/${key}_report.log"
tail -2000 "public/status/${key}_report.log" > "public/status/${key}_report.log.tmp"
mv "public/status/${key}_report.log.tmp" "public/status/${key}_report.log"
else
echo " $dateTime, $result, $time_total"
fi
done

if [[ $commit == true ]]
then
git config --global user.name 'fettle-mehatab'
git config --global user.email '[email protected]'
git add -A --force public/status/
git commit -am '[Automated] Update Health Check Logs'
git push
fi
echo "committing logs"
# git config --global user.name 'fettle-mehatab'
# git config --global user.email '[email protected]'
# git add -A --force public/status/
# git commit -am '[Automated] Update Health Check Logs'
# git push
fi
124 changes: 74 additions & 50 deletions src/incidents/index.tsx
Original file line number Diff line number Diff line change
@@ -1,55 +1,79 @@
import useIncidents from './hooks/useIncidents'
import type { NextPage } from 'next'
import Incidents from './types/Incident';
import MonthlyIncident from './types/MonthlyIncident';
import useIncidents from "./hooks/useIncidents";
import type { NextPage } from "next";
import Incidents from "./types/Incident";
import MonthlyIncident from "./types/MonthlyIncident";

const IncidentsSection: NextPage = () => {
const [monthlyIncidents, isIncidentsLoading] = useIncidents();
const [monthlyIncidents, isIncidentsLoading] = useIncidents();

const formatDate = (date: string) => {
return new Date(date).toLocaleString([], {
month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric'
});
}
const formatDate = (date: string) => {
return new Date(date).toLocaleString([], {
month: "short",
day: "numeric",
hour: "numeric",
minute: "numeric",
});
};

return (
<div className='mt-5'>
{
isIncidentsLoading ? (
<p>Loading...</p>
) : (
<div>
{
(monthlyIncidents as MonthlyIncident[]).map(incidents => (
<div className='mb-10' key={incidents.month}>
<p className='mr-5 text-2xl font-semibold leading-6 text-gray-900'>{incidents.month}</p>
<div className='mt-2 flex-1 h-px bg-gray-300' />
<div className='ml-6 border-l-4'>
{
(incidents.incidents as Incidents[]).map(incident => (
<div className='flex' key={incident.id}>
<div className='-ml-4 mt-6 flex rounded-full w-7 h-7 bg-gray-300'>
<svg xmlns="http://www.w3.org/2000/svg" width='14' height='17' viewBox='0 0 14 14' fill='none' className="m-auto fill-gray-500 text-disrupted">
<path d="M6.99999 2.3C10.14 2.3 12.7 4.86 12.7 8C12.7 11.14 10.14 13.7 6.99999 13.7C3.85999 13.7 1.29999 11.14 1.29999 8C1.29999 4.86 3.85999 2.3 6.99999 2.3ZM7 1C3.14 1 0 4.14 0 8C0 11.86 3.14 15 7 15C10.86 15 14 11.86 14 8C14 4.14 10.86 1 7 1ZM8 4H6V9H8V4ZM8 10H6V12H8V10Z" />
</svg>
</div>
<div className='items-center ml-3 mt-6'>
<p className='text-base font-semibold leading-6 text-gray-900'>{incident.title}</p>
<p className='text-sm text-gray-500'>This incident has been resolved.</p>
<p className='text-sm text-gray-500'>{formatDate(incident.created_at)} - {formatDate(incident.closed_at)}</p>
</div>
</div>
))
}
</div>
</div>
))
}
</div>
)
}
</div>
)
}
return (
<div className="mt-5">
{isIncidentsLoading ? (
<p>Loading...</p>
) : (
<div>
{(monthlyIncidents as MonthlyIncident[]).map((incidents) => (
<div className="mb-10" key={incidents.month}>
<p className="mr-5 text-2xl font-semibold leading-6 text-gray-900">{incidents.month}</p>
<div className="mt-2 flex-1 h-px bg-gray-300" />
<div className="ml-6 border-l-4">
{(incidents.incidents as Incidents[]).map((incident) => (
<div className="flex" key={incident.id}>
<div className="-ml-4 mt-6 flex rounded-full w-7 h-7 bg-gray-300">
<svg
xmlns="http://www.w3.org/2000/svg"
width="14"
height="17"
viewBox="0 0 14 14"
fill="none"
className="m-auto fill-gray-500 text-disrupted"
>
<path d="M6.99999 2.3C10.14 2.3 12.7 4.86 12.7 8C12.7 11.14 10.14 13.7 6.99999 13.7C3.85999 13.7 1.29999 11.14 1.29999 8C1.29999 4.86 3.85999 2.3 6.99999 2.3ZM7 1C3.14 1 0 4.14 0 8C0 11.86 3.14 15 7 15C10.86 15 14 11.86 14 8C14 4.14 10.86 1 7 1ZM8 4H6V9H8V4ZM8 10H6V12H8V10Z" />
</svg>
</div>
<div className="items-center ml-3 mt-6">
<p className="text-base font-semibold leading-6 text-gray-900">
{incident.title}
</p>
{incident.status === "closed" ? (
<div>
<p className="text-sm text-gray-500">
This incident has been resolved.
</p>
<p className="text-sm text-gray-500">
{formatDate(incident.created_at)} -{" "}
{formatDate(incident.closed_at)}
</p>
</div>
) : (
<div>
<p className="text-sm text-gray-500">
This incident is currently being investigated.
</p>
<p className="text-sm text-gray-500">
{formatDate(incident.created_at)}
</p>
</div>
)}
</div>
</div>
))}
</div>
</div>
))}
</div>
)}
</div>
);
};

export default IncidentsSection
export default IncidentsSection;

0 comments on commit 9214f40

Please sign in to comment.