Every server is "down!"
- Dominant language
- Python
- Stars
- 5
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
Hi. How are you? The project is really cool.
Is it possible to use this project without sending messages to Slack? I tried to use it and print the status in the terminal, but every server I entered was down, like "https://google.com" and "https://twitter.com".
Here is the main.py:
```
import logging
import socket
from fastapi import FastAPI
from fastapi_utils.tasks import repeat_every
from slack import WebClient
from serverpinger.config import settings
from serverpinger.constants import ServerState
app = FastAPI()
server_state = ServerState.UP
#client = WebClient(token=settings.SLACK_API_TOKEN)
uvicorn_logger = logging.getLogger("uvicorn")
logger = logging.getLogger(__name__)
logger.handlers = uvicorn_logger.handlers
logger.setLevel(logging.WARNING)
@app.on_event("startup")
@repeat_every(seconds=settings.PING_TIME, raise_exceptions=True)
def startup_event() -> None:
global server_state
host, port = settings.HOST, settings.PORT
#channel_id = settings.CHANNEL_ID
server = settings.SERVER_NAME
args = socket.getaddrinfo(host, port, socket.AF_INET, socket.SOCK_STREAM)
for family, socktype, proto, _, sockaddr in args:
s = socket.socket(family, socktype, proto)
try:
s.connect(sockaddr)
except socket.error:
if server_state == ServerState.UP:
print(f'{server} is down!')#client.chat_postMessage(channel=channel_id, text=f"{server} is down!")
logger.warning("%s changed from ON to OFF.", server)
server_state = ServerState.DOWN
else:
if server_state == ServerState.DOWN:
print(f'{server} is up!') #client.chat_postMessage(channel=channel_id, text=f"{server} is up!")
logger.warning("%s changed from OFF to ON.", server)
server_state = ServerState.UP
s.close()
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with main.py, especially startup_event and the socket.getaddrinfo/connect loop, and reproduce the reported behavior with the configured server values. Check how terminal status output is intended to work when Slack is disabled; done means reachable servers are reported as up and the application can run without sending Slack messages.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fastapi, python
- Domain
- backend, observability-sre
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100