Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
64 lines (57 sloc) 2 KB
// Copyright 2017 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Steeltoe.Common.HealthChecks;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Steeltoe.Management.Endpoint.Health
{
public class DefaultHealthAggregator : IHealthAggregator
{
public HealthCheckResult Aggregate(IList<IHealthContributor> contributors)
{
if (contributors == null)
{
return new HealthCheckResult();
}
var result = new HealthCheckResult();
foreach (var contributor in contributors)
{
HealthCheckResult h = null;
try
{
h = contributor.Health();
}
catch (Exception)
{
h = new HealthCheckResult();
}
if (h.Status > result.Status)
{
result.Status = h.Status;
}
if (!result.Details.ContainsKey(contributor.Id))
{
result.Details.Add(contributor.Id, h.Details);
}
else
{
// add the contribtor with a -n appended to the id
result.Details.Add(string.Concat(contributor.Id, "-", result.Details.Count(k => k.Key == contributor.Id)), h.Details);
}
}
return result;
}
}
}
You can’t perform that action at this time.