Files
AutopilotMonitor/src/Backend/AutopilotMonitor.Functions/Functions/Apps/GetAppSessionsFunction.cs
T
Oliver Kieselbach a0ad769231 RealmJoin packages count as app installs next to Intune apps
App install rows now carry their install channel. The ingest folds the RealmJoin
watcher's package started/completed events into AppInstallSummaries rows (channel
"realmjoin", keyed by scope + package id; duration = completion minus the observed
start). IME rows keep their key and have no channel column, so they read as before.

Every per-app aggregate groups on (channel, name): apps list, app analytics and
sessions (new ?source=, default ime), metrics/app, SLA top failing apps and the
version-regression radar (tracker key, episode key, bell link, ops event). The app
install SLA rate includes RealmJoin packages. The ESP-blocking stamp stays IME-only.
RealmJoin packages do not feed the software inventory or CVE correlation.

Web: a RealmJoin pill and an All / Intune / RealmJoin filter on Software > Installs,
the pill on app detail, Fleet Health and SLA, source-aware app links and PDF meta
line, and a hint in the empty Inventory tab. The pill moves out of InstallProgress
into a shared component. MCP: get_app_install_metrics names the source field.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 10:19:18 +02:00

85 lines
3.4 KiB
C#

using System.Net;
using AutopilotMonitor.Functions.Helpers;
using AutopilotMonitor.Shared.DataAccess;
using AutopilotMonitor.Shared.Models;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
namespace AutopilotMonitor.Functions.Functions.Apps
{
/// <summary>
/// GET /api/apps/{appName}/sessions?days=30&amp;status=failed&amp;model=...&amp;version=...&amp;offset=0&amp;limit=50
/// Returns paginated sessions that (tried to) install a given app for the caller's tenant.
/// </summary>
public class GetAppSessionsFunction
{
private const int DefaultLimit = 50;
private const int MaxLimit = 200;
private readonly ILogger<GetAppSessionsFunction> _logger;
private readonly IMetricsRepository _metricsRepo;
private readonly ISessionRepository _sessionRepo;
public GetAppSessionsFunction(
ILogger<GetAppSessionsFunction> logger,
IMetricsRepository metricsRepo,
ISessionRepository sessionRepo)
{
_logger = logger;
_metricsRepo = metricsRepo;
_sessionRepo = sessionRepo;
}
[Function("GetAppSessions")]
public async Task<HttpResponseData> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "apps/{appName}/sessions")] HttpRequestData req,
string appName)
{
try
{
var tenantId = TenantHelper.GetTenantId(req);
var decodedAppName = Uri.UnescapeDataString(appName ?? string.Empty);
if (string.IsNullOrWhiteSpace(decodedAppName))
{
return await req.BadRequestAsync("appName is required");
}
var query = req.Query;
var days = QueryParams.Int(query["days"], @default: 30, min: 1, max: 365);
if (!AppsAnalyticsHelper.TryParseSourceQueryParam(query["source"], out var source))
{
return await req.BadRequestAsync($"source must be one of: {string.Join(", ", AppInstallSources.All)}");
}
var statusFilter = (query["status"] ?? "all").Trim().ToLowerInvariant();
var modelFilter = query["model"];
var versionFilter = query["version"];
var offset = QueryParams.Int(query["offset"], @default: 0, min: 0, max: int.MaxValue);
var limit = QueryParams.Int(query["limit"], DefaultLimit, 1, MaxLimit);
var summaries = await AppsAnalyticsHelper.LoadSummariesAsync(_metricsRepo, tenantId, days);
var body = await AppsAnalyticsHelper.BuildSessionsResponseAsync(
summaries, _sessionRepo, decodedAppName, source, days,
statusFilter, modelFilter, versionFilter, offset, limit);
var response = req.CreateResponse(HttpStatusCode.OK);
await response.WriteAsJsonAsync(body);
return response;
}
catch (UnauthorizedAccessException ex)
{
_logger.LogWarning(ex, "Unauthorized apps/sessions request");
return await req.UnauthorizedAsync("Unauthorized");
}
catch (Exception ex)
{
return await req.InternalServerErrorAsync(_logger, ex, "GetAppSessions");
}
}
}
}