Skip to content

Commit

Permalink
feat: add route to give information about machine
Browse files Browse the repository at this point in the history
  • Loading branch information
adolfosp committed Jan 30, 2025
1 parent c044dfa commit 49e9950
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
1 change: 1 addition & 0 deletions Back-Orange-Finance/Orange-Finance/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
Expand Down
59 changes: 59 additions & 0 deletions Back-Orange-Finance/Orange-Finance/Endpoints/Info.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System.Net;
using System.Net.NetworkInformation;

namespace OrangeFinance.Endpoints;

public static class Info
{
public static void RegisterInfoEndpoints(this IEndpointRouteBuilder routes)
{
var farms = routes.MapGroup("/info");

farms.MapGet("", async () =>
{
var machineName = Environment.MachineName;
var osVersion = Environment.OSVersion.ToString();
var ipAddress = GetLocalIPAddress();
var macAddress = GetMacAddress();
var processId = Environment.ProcessId;

return (new
{
MachineName = machineName,
OSVersion = osVersion,
IPAddress = ipAddress,
MacAddress = macAddress,
ProcessId = processId,
Timestamp = DateTime.UtcNow
});

string GetLocalIPAddress()
{
string localIP = "N/A";
var host = Dns.GetHostEntry(Dns.GetHostName());
foreach (var ip in host.AddressList)
{
if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
localIP = ip.ToString();
break;
}
}
return localIP;
}

string GetMacAddress()
{
return NetworkInterface.GetAllNetworkInterfaces()
.Where(nic => nic.OperationalStatus == OperationalStatus.Up)
.Select(nic => nic.GetPhysicalAddress().ToString())
.FirstOrDefault() ?? "N/A";
}

}).Produces(statusCode: 200)
.MapToApiVersion(1)
.WithOpenApi();


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public static void RegisterApiVersion(this WebApplication app)

routeGroupBuilder.RegisterFarmEndpoints();
routeGroupBuilder.RegisterSecurityEndpoints();
routeGroupBuilder.RegisterInfoEndpoints();

}
}
8 changes: 4 additions & 4 deletions Back-Orange-Finance/Orange-Finance/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"DatabaseName": "Orange_Finance_Web"
},
"RedisSettings": {
"ConnectionString": "localhost:6379, abortConnect=false"
"ConnectionString": "192.168.18.54:6379, abortConnect=false"
},
"SqlServerSettings": {
"ConnectionString": "Server=sqlserver,1433;Trusted_Connection=false;Encrypt=False;Database=Orange_Finance_Web;User Id=sa;Password=SqlServer2022!"
"ConnectionString": "Server=192.168.18.54,1433;Trusted_Connection=false;Encrypt=False;Database=Orange_Finance_Web;User Id=sa;Password=SqlServer2022!"
},
"AllowedHosts": "*",
"Jwt": {
Expand Down Expand Up @@ -42,7 +42,7 @@
{
"Name": "Seq",
"Args": {
"serverUrl": "http://localhost:5341",
"serverUrl": "http://192.168.18.54:5341",
"apiKey": "qKuXFI8KHFla4b1wxbWl"
}
}
Expand All @@ -53,7 +53,7 @@
}
},
"RABBITMQ": {
"HostName": "host.docker.internal",
"HostName": "192.168.18.54",
"Password": "guest",
"Port": 5672,
"UserName": "guest"
Expand Down

0 comments on commit 49e9950

Please sign in to comment.