Last active
March 14, 2017 09:06
-
-
Save bastibeckr/3a823d9225d42c9422d34bea3de788c1 to your computer and use it in GitHub Desktop.
Basic nagios-check for ChronoSync Scheduler (Mac OSX)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env osascript -l JavaScript | |
ObjC.import('stdlib') | |
console.log = function() { | |
ObjC.import('Foundation'); | |
for (argument of arguments) { | |
$.NSFileHandle.fileHandleWithStandardOutput.writeData($.NSString.alloc.initWithString(String(argument) + "\n").dataUsingEncoding($.NSNEXTSTEPStringEncoding)); | |
} | |
} | |
function run(input, parameters) { | |
var sysEvents = Application('System Events'); | |
var scheduler = Application('ChronoSync Scheduler') | |
var scheduledItems = scheduler.scheduledItems() | |
var errors = [] | |
if( scheduler.enabled() === false ) { | |
errors.push('Scheduler is not enabled.') | |
} | |
for( var i in scheduledItems ) { | |
var item = scheduledItems[i] | |
var errorCount = item.lastSyncErrorCount() | |
if( item.active() === true && errorCount > 0 ) { | |
errors.push( item.description() + ' had ' + errorCount + ' errors on last sync! ') | |
} | |
} | |
if (errors.length > 0 ) { | |
console.log('CRITICAL - Errors: ' + errors.join(' ') ) | |
$.exit(2) | |
} else { | |
console.log('OK - ChronoSync Scheduler is active and there were no errors on last sync.') | |
$.exit(0) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SCRIPTRESULT=$(osascript << 'END' | |
set scheduler to application "ChronoSync Scheduler" | |
tell application "ChronoSync Scheduler" | |
set errors to {} | |
if enabled of scheduler = false then | |
copy "Scheduler is not enabled" to end of errors | |
end if | |
set scheduledItems to scheduled items | |
repeat with scheduledItem in scheduledItems | |
set errorCount to last sync error count of scheduledItem | |
if active of scheduledItem = true and errorCount > 0 then | |
copy "Error: " & description of scheduledItem to end of errors | |
end if | |
end repeat | |
if (count of errors) = 0 then | |
set output to "OK - ChronoSync Scheduler is enabled and last sync returned no errors." | |
else | |
set output to "CRITICAL - " & errors | |
end if | |
return output | |
end tell | |
END) | |
echo ${SCRIPTRESULT} | |
if [[ $SCRIPTRESULT =~ ^OK.+$ ]] ; then | |
exit 0 | |
else | |
exit 2 | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment