Comments (4)
@satterly This seems to work for me now. The weird thing is that the new environmental variables you're checking are unset, but equally the problem has gone away with the latest version on git. So I think this may have created a new bug, which has accidentally masked the old bug for me.
I think your new if statement may not evaluate what you intended.
The current code is:
if not sys.stdin.isatty() and (os.environ.get('TERM', None) or os.environ.get('PS1', None)):
I read this as: It's not a TTY and it either TERM or PS1 is truthy.
not
has a higher priority than and
in Python. So if I put in some more brackets to clarify the order:
if (not sys.stdin.isatty()) and (os.environ.get('TERM', None) or os.environ.get('PS1', None)):
I think you were aiming for: It's not a tty and neither TERM or PS1 is truthy, which would be:
if not sys.stdin.isatty() and not (os.environ.get('TERM', None) or os.environ.get('PS1', None)):
Or equally and perhaps clearer:
if not (sys.stin.isatty() or os.environ.get('TERM', None) or os.environ.get('PS1', None)):
I'm not sure whether I've got the wrong end of the stick or not here. If I'm on the right lines, then by fixing this new bug, the old bug will reappear.
I'd like to suggest that the piping behaviour be disabled by default and enabled by it's own CLI option (e.g. --pipe-input json_lines
). It looks like it's almost impossible to tell the difference between a job running a cron environment and a pipe.
from python-alerta-client.
not
only applies to the first test (ie. the isatty()
check) otherwise both these statements would give the same result...
>>> not True and False
False
>>> not (True and False)
True
What I'm checking for is ...
IF it does not have a TTY
THEN it is either cron or data is being piped to stdin
IF it is a terminal (ie. is `TERM` or `PS1` set?)
THEN read data from stdin
ELSE
assume it is a terminal console, or cron, and run send with command-line args
So I'm pretty sure this change works as intended but let me know if this still doesn't make sense.
from python-alerta-client.
@satterly My mistake. Fully understand why you've done this and how it works now. Bug indeed fixed and there is no new bug. Sorry about the false alarm!
from python-alerta-client.
No problem. It was good to clarify, in my own head, what was going on just to be sure.
from python-alerta-client.
Related Issues (20)
- Configurable timeout for alerts created from heartbeats
- Get config request ignores "SSL verify" setting
- severity used to close stale heartbeat alerts is hardcoded to 'normal' HOT 2
- Handle when config cannot be loaded from server
- Error when creating new users HOT 1
- output=silent (crontab mode) HOT 7
- Alerts on heartbeat are not triggered HOT 6
- Add generating heartbeat alerts to python SDK HOT 1
- Wheel name and python package name are different HOT 4
- `alerta heartbeats --alert` broken HOT 4
- TypeError: Object of type 'function' is not JSON serializable from CLI when running heartbeat alert HOT 1
- TypeError: Object of type 'function' is not JSON serializable from CLI when running heartbeat alert HOT 2
- SDK passing page size as "None" if not set
- alerta delete not removing all alerts HOT 1
- TypeError: 'User' object is not subscriptable
- Cron job for stale or slow heartbeats do not accept arguments specified in the documentation HOT 1
- Set alarm status in send_alarm HOT 3
- Add Python3 typing
- Alerta doesn't return all alert with get_alerts
- Unable to handshake between alerta server and Web UI HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-alerta-client.