-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_mi_mics_ldapsynclog
101 lines (87 loc) · 4.34 KB
/
check_mi_mics_ldapsynclog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
#
# MobileIron Core Ldap Sync Log Diagnostics Nagios check script
#
# Copyright (C) 2016 Gary McConnell - Clever Consulting Srl.
# www.clevermobile.it
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# ####################################################
# Set the script name variables
# ####################################################
mSCRIPTNAME=$(basename $0)
mTEMP="$mSCRIPTNAME.XXXXXXXXXX"
# ####################################################
# Check for correct number of arguments/variables set
# ####################################################
if [ -z "$3" ]
then
echo "usage: check_mi_mics_ldapsynclog <HOSTNAME> <USERNAME> <PASSWORD>"
exit 3
fi
# ####################################################
# Set the script Variables
# ####################################################
mVSP=$1
mVSP_USERNAME=$2
mVSP_PASSWORD=$3
mTMP_DIR="/tmp"
mPLUGIN_DIR="/usr/lib64/nagios/plugins"
mCOOKIES=$(mktemp "$mTMP_DIR/$mTEMP.Cookies")
mFILETMP1=$(mktemp "$mTMP_DIR/$mTEMP.1")
mFILETMP2=$(mktemp "$mTMP_DIR/$mTEMP.2")
mFILETMP3=$(mktemp "$mTMP_DIR/$mTEMP.3")
mFILEJSON=$(mktemp "$mTMP_DIR/$mTEMP.JSON")
mLIBJSON=$mPLUGIN_DIR/check_mi_JSON
# ####################################################
# Remote Call to MobileIron Service Login
# ####################################################
curl -k --data "j_username=$mVSP_USERNAME&j_password=$mVSP_PASSWORD&spid=&submit=LOGIN" -H "Referer: https://$mVSP/mics/login.jsp" https://$mVSP/mics/j_spring_security_check --cookie-jar $mCOOKIES --location > $mFILETMP1
# get NONCE Value
mCSRFKEY=$(cat $mFILETMP1 | grep csrfKey | tr -s " " | cut -d "\"" -f2)
mCSRFVALUE=$(cat $mFILETMP1 | grep csrfNonce | tr -s " " | cut -d "\"" -f2)
# ####################################################
# Remote Call to MobileIron LDAP Connector Status
# ####################################################
curl -k "https://$mVSP/mics/mics.html?_dc=`date +%s`&action=getLdapSyncHistory&command=getLdapSyncHistory" --cookie $mCOOKIES -H "$mCSRFKEY: $mCSRFVALUE" --location > $mFILETMP2
mLDAPSYNCLOGSTATUS=$(cat $mFILETMP2 | $mLIBJSON -b | grep "\[\"results\",0,\"status\"\]" | cut -f2 | xargs)
mLDAPSYNCLOGENDDATE=$(cat $mFILETMP2 | $mLIBJSON -b | grep "\[\"results\",0,\"endDate\"\]" | cut -f2 | xargs)
mLDAPSYNCLOGDURATION=$(cat $mFILETMP2 | $mLIBJSON -b | grep "\[\"results\",0,\"duration\"\]" | cut -f2 | xargs)
mLDAPSYNCLOGSYNCEDUSERS=$(cat $mFILETMP2 | $mLIBJSON -b | grep "\[\"results\",0,\"syncedUsers\"\]" | cut -f2 | xargs)
mLDAPSYNCLOGTOTALUSERS=$(cat $mFILETMP2 | $mLIBJSON -b | grep "\[\"results\",0,\"totalUsers\"\]" | cut -f2 | xargs)
mLDAPSYNCLOGSYNCEDGROUPS=$(cat $mFILETMP2 | $mLIBJSON -b | grep "\[\"results\",0,\"syncedGroups\"\]" | cut -f2 | xargs)
mLDAPSYNCLOGTOTALGROUPS=$(cat $mFILETMP2 | $mLIBJSON -b | grep "\[\"results\",0,\"totalGroups\"\]" | cut -f2 | xargs)
# ####################################################
# Delete all files created during process
# ####################################################
rm -rf $mCOOKIES
rm -rf $mFILETMP1
rm -rf $mFILETMP2
rm -rf $mFILETMP3
rm -rf $mFILEJSON
# ####################################################
# Exit script
# ####################################################
if [ "$mLDAPSYNCLOGSTATUS" != "Success" ]
then
mFINALSTRING="Failure in ldapsync.log"
echo "$mFINALSTRING | totalgroups=$mLDAPSYNCLOGTOTALGROUPS;0;20;0;100"
exit 2
else
mFINALSTRING="Status: $mLDAPSYNCLOGSTATUS - End Date: $mLDAPSYNCLOGENDDATE - Duration: $mLDAPSYNCLOGDURATION - Users: $mLDAPSYNCLOGSYNCEDUSERS/$mLDAPSYNCLOGTOTALUSERS - Groups: $mLDAPSYNCLOGSYNCEDGROUPS/$mLDAPSYNCLOGTOTALGROUPS"
echo "$mFINALSTRING | totalgroups=$mLDAPSYNCLOGTOTALGROUPS"
#mRANDNUM=$[ 1 + $[ RANDOM % 10 ]]
#echo "$mFINALSTRING | totalgroups=$mRANDNUM"
exit 0
fi