Python Health Check Service
Applications often need to expose endpoints that indicate their operational status to external monitoring systems. This challenge involves building a simple health check mechanism in Python that can report the status of various internal components.
Problem Description
You need to create a Python function that acts as a health checker. This function will receive a list of potential "services" (represented as strings) and for each service, it should attempt to determine if it's healthy. A service is considered healthy if a predefined condition is met. The function should return a dictionary where keys are the service names and values are their respective health statuses (either "healthy" or "unhealthy").
Key Requirements:
- The health checker function should accept a list of service names as input.
- For each service, you need to simulate a check. For simplicity in this challenge, we'll define specific rules for determining health.
- The function must return a dictionary mapping service names to their health status ("healthy" or "unhealthy").
Expected Behavior:
- If a service name is "database", it's considered healthy if its status is not explicitly "down".
- If a service name is "api", it's considered healthy if its status is not explicitly "maintenance".
- If a service name is "cache", it's always considered healthy.
- If a service name is "queue", it's considered healthy if its status is not explicitly "full".
- For any other service name, assume it is "healthy" by default.
Edge Cases:
- An empty list of services should result in an empty dictionary.
- Service names might be case-sensitive according to the rules above.
Examples
Example 1:
Input: ["database", "api", "cache"]
Output: {"database": "healthy", "api": "healthy", "cache": "healthy"}
Explanation: All services are healthy based on the default rules.
Example 2:
Input: ["database", "api", "queue"]
Output: {"database": "healthy", "api": "healthy", "queue": "healthy"}
Explanation: Simulating a normal state for all.
Example 3:
Input: ["database", "api", "queue"]
Output: {"database": "unhealthy", "api": "unhealthy", "queue": "healthy"}
Explanation: For this example, imagine the "database" is "down" and the "api" is in "maintenance". The "queue" remains healthy.
Example 4:
Input: []
Output: {}
Explanation: An empty input list results in an empty output dictionary.
Constraints
- The input
serviceswill be a list of strings. - The number of services in the list will not exceed 100.
- Service names will consist of alphanumeric characters and underscores.
- The output dictionary will have at most 100 key-value pairs.
Notes
To implement the conditional checks (e.g., "database" being unhealthy if "down"), you will need to simulate the status of these services. A good approach would be to create helper functions or use a dictionary to represent the current state of each service. For this challenge, you can hardcode or define these simulated states within your solution. For instance, you might have a service_statuses dictionary like {"database": "down", "api": "maintenance"} to test the unhealthy scenarios.