Files
shelly-exporter/ShellyExporter/Program.cs
2024-01-12 22:36:42 +01:00

55 lines
1.2 KiB
C#

using System.Text;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Hosting;
using ShellyExporter;
using System.Xml.Linq;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
if (!builder.Environment.IsDevelopment())
{
builder.WebHost.UseKestrel();
builder.WebHost.UseUrls(builder.Configuration["Kst:Url"]);
}
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Map("/metrics", () =>
{
var sb = new StringBuilder();
foreach (var host in builder.Configuration.GetSection("Hosts").GetChildren())
{
sb.Append(Metrics.Get($"http://{host["ip"]}",
host.Path.Replace("Hosts:", ""),
(Metrics.Version)Convert.ToInt16(host["version"]),
(Metrics.Type)Convert.ToInt16(host["type"])).Result);
}
return sb.ToString();
});
app.Run();