Skip to content
This repository has been archived by the owner on Oct 16, 2023. It is now read-only.

Add logout method #3

Open
wants to merge 112 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
8a1963f
add ZabbixAPIHistory class with history.get and history.delete functions
gescheit Feb 2, 2011
04f85b2
update usergroup functions to current
gescheit Feb 15, 2011
203ae7b
added Already_Exists exception
Apr 6, 2011
bfcf2a1
added timeout variable for urllib2
gescheit May 5, 2011
840afd4
urllib2 socket timeout fixed
gescheit Aug 13, 2011
2e8e7bd
graph.add method renamed to graph.create
Aug 18, 2011
6b6ddfd
Add hostgroup exists call
rday Aug 23, 2011
195184a
Add proxy API
rday Aug 23, 2011
00d88c3
Merge pull request #1 from flashvoid/graph_create
gescheit Aug 26, 2011
33dea23
Merge pull request #2 from rday/master
gescheit Aug 26, 2011
9b886a9
added recent_query() function. this function return last query, depen…
gescheit Aug 27, 2011
6893ab0
Merge branch 'master' of github.com:gescheit/scripts
gescheit Aug 27, 2011
39951df
remove scripts unrelated to Zabbix Python API
dlbewley Oct 15, 2011
893ddc7
brief intro and links to zabbix docs
dlbewley Oct 15, 2011
1f5fd37
Merge pull request #4 from dlbewley/master
gescheit Oct 22, 2011
19f1834
Prefer simplejson over json
ekohl Nov 15, 2011
9672cea
fixed usermacro functions
gescheit Nov 20, 2011
e468640
Change user.add api method to user.create since the api method is now…
rrtj3 Nov 23, 2011
aac81e4
Merge pull request #6 from romeotheriault/master
gescheit Nov 23, 2011
551529b
Merge pull request #5 from ekohl/master
gescheit Nov 23, 2011
0b216bd
Introduced new schema with one function for all methods in class.
gescheit Dec 1, 2011
4ff1238
fixed result not returned in item calls
gescheit Dec 1, 2011
c7ededd
fixed list instead of dictionary in opts in API item
gescheit Dec 1, 2011
7b854d9
added new universal method in API Host
gescheit Dec 1, 2011
207d33b
chaned all ZabbixAPI classes to new style
gescheit Dec 4, 2011
b393d81
pep8 compliant
gescheit Dec 4, 2011
02ce3f5
initial support of python3
gescheit Dec 28, 2011
f602004
__getattr__ moved to parent class
gescheit Jan 6, 2012
bc8b63f
use ZabbixAPISubClass with parameters instead inheritance
gescheit Jan 6, 2012
d38ad49
cleanup and PEP8 complaint
gescheit Jan 6, 2012
eb8c420
add apiinfo method
gescheit Jun 26, 2012
ca2b621
add new methods from zabbix 2
gescheit Jun 28, 2012
5c6bb28
added workaround for import function in configuration method.
gescheit Jul 6, 2012
9ef9b5a
add setup.py and .gitignore
Aug 23, 2012
27966de
Merge pull request #7 from aababilov/master
gescheit Aug 23, 2012
70c5f81
refresh documentation
gescheit Sep 12, 2012
302eca2
Merge branch 'master' of github.com:gescheit/scripts
gescheit Sep 12, 2012
29aca39
fix server path in example
gescheit Sep 12, 2012
bc369cd
Added the hostinterface API call.
untergeek Nov 7, 2012
e02d757
Merge pull request #11 from untergeek/master
gescheit Nov 9, 2012
61768cd
Update zabbix/zabbix_api.py
jlegido Dec 4, 2012
8cdeb75
add hostinterface class
gescheit Dec 5, 2012
963fa09
Merge branch 'patch-1' of https://github.com/caraconan/scripts
gescheit Dec 5, 2012
59abbc1
Merge pull request #12 from caraconan/patch-1
gescheit Dec 5, 2012
3d3745a
Merge branch 'master' of github.com:gescheit/scripts
gescheit Dec 5, 2012
15514b2
add itemprototype, graphprototype, triggerprototype
gescheit Dec 25, 2012
86526bc
Add support for the webcheck method.
sjbronner Mar 20, 2013
32552bf
Merge pull request #15 from sjbronner/master
gescheit Mar 20, 2013
403780b
Raise exception on API request error.
Mar 27, 2013
f558314
Merge pull request #16 from fossilet/master
gescheit Mar 29, 2013
d668e1b
Add zabbix screenitem
somsak Jul 18, 2013
f024fbf
Example script for automatic screen creation
somsak Jul 18, 2013
5db2151
Merge pull request #17 from somsak/master
gescheit Jul 19, 2013
c59c6d3
Create README.md
gescheit Oct 13, 2013
5994df7
initial
gescheit Oct 13, 2013
a665a96
initial
gescheit Oct 13, 2013
5b247d1
fix error message
gescheit Oct 13, 2013
b92600f
add readme
gescheit Oct 13, 2013
35dce54
Update and rename README.md to README
gescheit Oct 13, 2013
a89fd48
Update README
gescheit Oct 13, 2013
2b22dfa
Update and rename README to README.md
gescheit Oct 13, 2013
2ecc4fa
Update README.md
gescheit Oct 13, 2013
65def1a
Update code and README to work with zabbix-2.4
evgkrsk Oct 1, 2014
ac27a15
Merge pull request #18 from evgkrsk/zabbix2.4
gescheit Oct 12, 2014
e6f50ee
Fixed crlf issue
gescheit Feb 1, 2015
dcf4e31
added APITimeout exception
gescheit Feb 1, 2015
b433aa3
removed unused dojson()
gescheit Feb 1, 2015
995e321
rename dojson2() to dojson()
gescheit Feb 1, 2015
e5addb6
fix indents
gescheit Feb 1, 2015
6d6413e
delete hardcoded API methods
gescheit Feb 1, 2015
bd1e968
bump version
gescheit Feb 1, 2015
20818dc
update README
gescheit Feb 1, 2015
ae7aef1
move examples to examples dir
gescheit Feb 1, 2015
8e69a8a
update readme
gescheit Feb 3, 2015
d39e25c
README -> README.md
gescheit Feb 3, 2015
0d9f03b
add README.md
gescheit Feb 3, 2015
cf16b22
remove unwanted declaration
gescheit Feb 12, 2015
461947c
add classifiers
gescheit Feb 12, 2015
2148ac9
update to 0.3
gescheit Feb 12, 2015
936a812
README is now README.md
evgkrsk Nov 19, 2015
4456158
Add support for unverified/selfsigned SSL certificates
evgkrsk Nov 19, 2015
2a5e35c
Merge pull request #20 from evgkrsk/validate_certs
gescheit Nov 19, 2015
fc56a6b
Merge pull request #19 from evgkrsk/readme-typo
gescheit Nov 20, 2015
ef1ee59
raise ZabbixAPIException instead of 'e'
mprenditore Feb 1, 2017
b51b8c6
pep8 compliant
mprenditore Feb 1, 2017
7a6f0c6
better exception handling
mprenditore Feb 1, 2017
8407485
add 3.0 and 3.2
gescheit Feb 8, 2017
8c6e70a
Merge pull request #25 from mprenditore/master
gescheit Feb 8, 2017
10c7c73
handle internal server errors
jsoref Mar 15, 2017
eac9391
Merge pull request #26 from jsoref/ise
gescheit Mar 19, 2017
c1a892f
fixing SyntaxError in line 259, should be elif NOTelsif
mkrug1981 May 4, 2017
07efefd
Merge pull request #27 from mkrug1981/master
gescheit May 4, 2017
a9b320e
fix api_version()
gescheit Jul 12, 2017
06a7cd7
release 0.5
gescheit Sep 19, 2017
45d20e4
fix pypi doc
gescheit Sep 19, 2017
386aa22
add README.md to MANIFEST
gescheit Sep 19, 2017
fa3bec1
add logout method
RobinChenMBP Apr 24, 2018
9ff9617
Fix python3 authorization problem
empire Dec 26, 2018
34964f4
Merge pull request #32 from empire/fix-python3
gescheit Mar 25, 2019
9d1943b
Merge pull request #31 from RobinChenMBP/master
gescheit Mar 25, 2019
2dddc0f
Update setup version
empire Apr 6, 2019
721dba6
Merge pull request #33 from empire/patch-1
gescheit Apr 12, 2019
13b085e
Added token based authentication
red-tux Sep 22, 2022
b05d608
Merge pull request #36 from red-tux/master
gescheit Oct 4, 2022
4fce611
pypandoc call fix
artemyevav Oct 24, 2022
a3959e9
version bump
artemyevav Oct 28, 2022
dd1283a
Merge pull request #38 from artemyevav/master
gescheit Nov 8, 2022
6d10ab1
fix new username field name
gescheit Apr 28, 2023
1cf7abb
fix
gescheit Apr 28, 2023
8b06cc4
Merge pull request #39 from gescheit/update
gescheit Apr 28, 2023
99dbb39
bump version
gescheit Apr 28, 2023
575e618
Merge pull request #40 from gescheit/update
gescheit Apr 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*.py[co]
.idea
*.swp
*~
build
dist
*.egg-info
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
python zabbix api - https://github.com/gescheit/scripts/tree/master/zabbix

4 changes: 4 additions & 0 deletions checks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
functions.sh - functions for locking and caching
disksmart.sh - check SMART of all disks in system
- Work under FreeBSD and linux
- Use caching and locking
95 changes: 95 additions & 0 deletions checks/disksmart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/sh
# check SMART of all disks in system
BASENAME=$(dirname $0)
. ${BASENAME}/functions.sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/zabbix/bin
RES=""
ME="disksmart_check"
TIMEOUT=600
ERRLOG_COUNT_THRESHOLD=100
if [ `which smartctl >/dev/null; echo $?` -ne 0 ]; then
echo "no smartctl"
exit 1
fi

checkSmartExitStatus()
{
STATUS=$1
#if [ $(($STATUS & 1<<0)) -gt 0 ]; then echo "Command line did not parse"; fi
# if [ $(($STATUS & 1<<1)) -gt 0 ]; then echo "Device open failed"; fi
if [ $(($STATUS & 1<<2)) -gt 0 ]; then echo "Some command to the disk failed, or there was a checksum error in a SMART data structure"; fi
if [ $(($STATUS & 1<<3)) -gt 0 ]; then echo "DISK FAILING"; fi
if [ $(($STATUS & 1<<4)) -gt 0 ]; then echo "found prefail Attr <= threshold"; fi
# if [ $(($STATUS & 1<<5)) -gt 0 ]; then echo "Some attributes have been <= threshold at some time in the past"; fi
if [ $(($STATUS & 1<<7)) -gt 0 ]; then echo "self-test log contains records of errors"; fi
}


CACHE=`getFromCache "$ME" $TIMEOUT`
if [ -z "$CACHE" ]; then

lockf ${ME} 15
[ $? -eq 0 ] || exit # unable to get lockfile
DISKS="`sudo smartctl --scan-open`"
if [ $? -ne 0 ]; then # old smartctl
if [ `uname` = "Linux" ]; then
DISKS="`ls -1 /dev/ | grep -E '^sd[a-z]$' 2>/dev/null | sed 's|^|/dev/|' | sed 's|$|,|'`"
elif [ `uname` = "FreeBSD" ]; then
DISKS="`ls -1 /dev/ | grep -E '^(ad[0-9]+|da[0-9]+|ada[0-9]+)$' 2>/dev/null | sed 's|^|/dev/|' | sed 's|$|,|'`"
fi
else
DISKS="`echo \"$DISKS\" | sed 's|\ [\#\[].*|,|'`"
fi
OIFS="${IFS}"
NIFS=$","

IFS="${NIFS}"

for DISK in ${DISKS}; do
IFS='${OIFS}'
if [ -z "$DISK" ]; then
continue
fi
DISK=${DISK%%\#*}
DISK=${DISK%-*}
DISK=`echo $DISK| xargs`
sudo smartctl -q silent -a $DISK 2>/dev/null
SMARTSTATUS=$?
ERRLOG_COUNT=0
if [ $SMARTSTATUS -ne 0 ]; then
SMARTSTR=`checkSmartExitStatus \$SMARTSTATUS`
if [ $((${SMARTSTATUS} & 1<<2)) -gt 0 ]; then
sudo smartctl -a $DISK 2>/dev/null | grep -qE '(Vendor.*VMware|Vendor.*SUPER|Device.*DELL|device.*CD/DVD|Device.*processor|Device.*enclosure|Product.*Array|Virtual.*disk)'
if [ $? -eq 0 ]; then
continue
fi
sudo smartctl -i -A -l error -l selftest $DISK 2>/dev/null 1>/dev/null # try without health check
if [ $? -eq 0 ]; then
continue
fi
fi
if [ $((${SMARTSTATUS} & 1<<6)) -gt 0 ]; then
ERRLOG_COUNT="`sudo smartctl -l error $DISK 2>/dev/null | grep Error\ Count`"
ERRLOG_COUNT=${ERRLOG_COUNT##*: }
ERRLOG_COUNT=${ERRLOG_COUNT%% *}
fi
if [ -n "${SMARTSTR}" -o \( ${ERRLOG_COUNT} -gt ${ERRLOG_COUNT_THRESHOLD} \) ]; then
SMARTSTR="ton of errors in log"
RES="${RES}${DISK} ${SMARTSTR}
"
fi
fi
IFS="${NIFS}"
done
IFS="${OIFS}"
if [ -z "$RES" ]; then
RES="OK"
fi

writeToCache "$ME" "$RES"
unlockf $ME
else
RES=${CACHE}
fi

echo "$RES" | tr -s "\n\n" "\n"
71 changes: 71 additions & 0 deletions checks/functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/sh

LOCKDIR="/tmp"
CACHEDIR=$LOCKDIR

getFromCache()
{
CACHEFILE="$CACHEDIR/$1.cache"
TIMEOUT="$2"
CURRENTTIME="`date +%s`"
if [ -s ${CACHEFILE} ]; then
CACHEDATA=`cat ${CACHEFILE}`
OLDDATATIME=${CACHEDATA%%,*}
OLDDATA=${CACHEDATA#*,}

if [ $OLDDATATIME -gt $((CURRENTTIME-TIMEOUT)) ]; then
echo "$OLDDATA"
return 0
else
return 1
fi
fi
}

writeToCache()
{
CACHEFILE="$CACHEDIR/$1.cache"
DATA="$2"
CURRENTTIME="`date +%s`"
echo "$CURRENTTIME,$DATA" > "$CACHEFILE"
[ "`id -u -n`" = "zabbix" ] || chown zabbix "$CACHEFILE"
return 0
}

lockf()
{
LOCKFILE="$LOCKDIR/$1.lock"
if [ -n "$2" ]; then
RETRY=$2
else
RETRY=1
fi
while [ $RETRY -gt 0 ]; do
RETRY=`expr $RETRY - 1`
if (set -o noclobber; echo "$$" > "$LOCKFILE") 2> /dev/null; then
trap 'rm -f "$LOCKFILE"; exit $?' INT TERM EXIT
return 0
fi
if [ -f "$LOCKFILE" ]; then
kill -0 `cat "$LOCKFILE"` 1>/dev/null 2>&1
if [ $? -ne 0 ]; then
rm -f "$LOCKFILE"
if [ $? -ne 0 ]; then
echo "unable to remove lock"
return 1
fi
fi
fi
sleep 1
done
echo "Locking failed. Held by $(cat $LOCKFILE)"
return 1
}

unlockf()
{
LOCKFILE="$LOCKDIR/$1.lock"
rm -f "$LOCKFILE"
trap - INT TERM EXIT
return 0
}
Loading