chook 1.0.0.b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +174 -0
  3. data/README.md +259 -0
  4. data/bin/chook-server +28 -0
  5. data/data/sample_handlers/RestAPIOperation-executable +91 -0
  6. data/data/sample_handlers/RestAPIOperation.rb +45 -0
  7. data/data/sample_handlers/SmartGroupComputerMembershipChange-executable +47 -0
  8. data/data/sample_handlers/SmartGroupComputerMembershipChange.rb +33 -0
  9. data/data/sample_jsons/ComputerAdded.json +27 -0
  10. data/data/sample_jsons/ComputerCheckIn.json +27 -0
  11. data/data/sample_jsons/ComputerInventoryCompleted.json +27 -0
  12. data/data/sample_jsons/ComputerPolicyFinished.json +27 -0
  13. data/data/sample_jsons/ComputerPushCapabilityChanged.json +27 -0
  14. data/data/sample_jsons/JSSShutdown.json +14 -0
  15. data/data/sample_jsons/JSSStartup.json +14 -0
  16. data/data/sample_jsons/MobileDeviceCheckIn.json +26 -0
  17. data/data/sample_jsons/MobileDeviceCommandCompleted.json +26 -0
  18. data/data/sample_jsons/MobileDeviceEnrolled.json +26 -0
  19. data/data/sample_jsons/MobileDevicePushSent.json +26 -0
  20. data/data/sample_jsons/MobileDeviceUnEnrolled.json +26 -0
  21. data/data/sample_jsons/PatchSoftwareTitleUpdated.json +14 -0
  22. data/data/sample_jsons/PushSent.json +11 -0
  23. data/data/sample_jsons/README +4 -0
  24. data/data/sample_jsons/RestAPIOperation.json +15 -0
  25. data/data/sample_jsons/SCEPChallenge.json +10 -0
  26. data/data/sample_jsons/SmartGroupComputerMembershipChange.json +13 -0
  27. data/data/sample_jsons/SmartGroupMobileDeviceMembershipChange.json +13 -0
  28. data/lib/chook.rb +38 -0
  29. data/lib/chook/configuration.rb +198 -0
  30. data/lib/chook/event.rb +153 -0
  31. data/lib/chook/event/handled_event.rb +154 -0
  32. data/lib/chook/event/handled_event/handlers.rb +206 -0
  33. data/lib/chook/event/test_event.rb +140 -0
  34. data/lib/chook/event_handling.rb +40 -0
  35. data/lib/chook/event_testing.rb +43 -0
  36. data/lib/chook/foundation.rb +33 -0
  37. data/lib/chook/handled_events.rb +33 -0
  38. data/lib/chook/handled_subjects.rb +33 -0
  39. data/lib/chook/procs.rb +46 -0
  40. data/lib/chook/server.rb +121 -0
  41. data/lib/chook/server/routes.rb +27 -0
  42. data/lib/chook/server/routes/handle_webhook_event.rb +39 -0
  43. data/lib/chook/server/routes/home.rb +37 -0
  44. data/lib/chook/subject.rb +143 -0
  45. data/lib/chook/subject/computer.rb +121 -0
  46. data/lib/chook/subject/handled_subject.rb +84 -0
  47. data/lib/chook/subject/jss.rb +56 -0
  48. data/lib/chook/subject/mobile_device.rb +115 -0
  49. data/lib/chook/subject/patch_software_title_update.rb +55 -0
  50. data/lib/chook/subject/push.rb +38 -0
  51. data/lib/chook/subject/randomizers.rb +506 -0
  52. data/lib/chook/subject/rest_api_operation.rb +62 -0
  53. data/lib/chook/subject/samplers.rb +360 -0
  54. data/lib/chook/subject/scep_challenge.rb +32 -0
  55. data/lib/chook/subject/smart_group.rb +50 -0
  56. data/lib/chook/subject/test_subject.rb +195 -0
  57. data/lib/chook/subject/validators.rb +117 -0
  58. data/lib/chook/test_events.rb +33 -0
  59. data/lib/chook/test_subjects.rb +33 -0
  60. data/lib/chook/version.rb +32 -0
  61. metadata +129 -0
@@ -0,0 +1,91 @@
1
+ #!/bin/bash
2
+
3
+ ### Copyright 2017 Pixar
4
+
5
+ ###
6
+ ### Licensed under the Apache License, Version 2.0 (the "Apache License")
7
+ ### with the following modification; you may not use this file except in
8
+ ### compliance with the Apache License and the following modification to it:
9
+ ### Section 6. Trademarks. is deleted and replaced with:
10
+ ###
11
+ ### 6. Trademarks. This License does not grant permission to use the trade
12
+ ### names, trademarks, service marks, or product names of the Licensor
13
+ ### and its affiliates, except as required to comply with Section 4(c) of
14
+ ### the License and to reproduce the content of the NOTICE file.
15
+ ###
16
+ ### You may obtain a copy of the Apache License at
17
+ ###
18
+ ### http://www.apache.org/licenses/LICENSE-2.0
19
+ ###
20
+ ### Unless required by applicable law or agreed to in writing, software
21
+ ### distributed under the Apache License with the above modification is
22
+ ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23
+ ### KIND, either express or implied. See the Apache License for the specific
24
+ ### language governing permissions and limitations under the Apache License.
25
+ ###
26
+ ###
27
+
28
+ # NOTE: Native bash doesn't have any easy way to parse JSON.
29
+ # Instead, you should really use a tool like 'jq' https://stedolan.github.io/jq/.
30
+ #
31
+ # If you have jq, set its correct path in the JQ variable below.
32
+ #
33
+ # If not, this script will use a hacky, VERY inappropriate and breakable
34
+ # way to parse JSON!
35
+ # But, it works enough to demonstrate the idea of using bash to write a handler.
36
+
37
+ # Enter your path to jq
38
+ JQ=/usr/local/bin/jq
39
+
40
+ # read all of stdin into a variable
41
+ while read line ; do JSON="$JSON $line" ; done
42
+
43
+ # use jq if we can
44
+ if [ -x "$JQ" ] ; then
45
+
46
+ hookname=`echo $JSON | "$JQ" -r '.webhook.name'`
47
+ authname=`echo $JSON | "$JQ" -r '.event.authorizedUsername'`
48
+ otype=`echo $JSON | "$JQ" -r '.event.objectTypeName'`
49
+ oname=`echo $JSON | "$JQ" -r '.event.objectName'`
50
+ oid=`echo $JSON | "$JQ" -r '.event.objectID'`
51
+ optype=`echo $JSON | "$JQ" -r '.event.restAPIOperationType'`
52
+
53
+ # otherwise, hacky bash parsing.
54
+ else
55
+
56
+ # use a comma as the field separator for the for-loop
57
+ IFS=','
58
+
59
+ # loop thru comma-separated chunks
60
+ for chunk in $JSON ; do
61
+ hookre='"name": "(.+)"'
62
+ [[ $chunk =~ $hookre ]] && hookname="${BASH_REMATCH[1]}"
63
+ authunamere='"authorizedUsername": "(.+)"'
64
+ [[ $chunk =~ $authunamere ]] && authname="${BASH_REMATCH[1]}"
65
+ otypere='"objectTypeName": "(.+)"'
66
+ [[ $chunk =~ $otypere ]] && otype="${BASH_REMATCH[1]}"
67
+ onamere='"objectName": "(.+)"'
68
+ [[ $chunk =~ $onamere ]] && oname="${BASH_REMATCH[1]}"
69
+ oidre='"objectID": (.+)'
70
+ [[ $chunk =~ $oidre ]] && oid="${BASH_REMATCH[1]}"
71
+ optypere='"restAPIOperationType": "(.+)"'
72
+ [[ $chunk =~ $optypere ]] && optype="${BASH_REMATCH[1]}"
73
+ done
74
+
75
+ fi # if [ -x "$JQ" ] ; then
76
+
77
+ # make an 'action' out of the operation type
78
+ # or exit if we don't know or don't care.
79
+ case $optype in
80
+ GET) exit 0 ;;
81
+ PUT) action=create ;;
82
+ POST) action=update ;;
83
+ DELETE) action=delete ;;
84
+ *) exit 15 ;;
85
+ esac
86
+
87
+ # output
88
+ echo "The JSS WebHook named '${hookname}' was just triggered.
89
+ It indicates that Casper user '${authname}' just used the JSS API to ${action}
90
+ the JSS ${otype}named '${oname}' (id ${oid})
91
+ "
@@ -0,0 +1,45 @@
1
+ ### Copyright 2017 Pixar
2
+
3
+ ###
4
+ ### Licensed under the Apache License, Version 2.0 (the "Apache License")
5
+ ### with the following modification; you may not use this file except in
6
+ ### compliance with the Apache License and the following modification to it:
7
+ ### Section 6. Trademarks. is deleted and replaced with:
8
+ ###
9
+ ### 6. Trademarks. This License does not grant permission to use the trade
10
+ ### names, trademarks, service marks, or product names of the Licensor
11
+ ### and its affiliates, except as required to comply with Section 4(c) of
12
+ ### the License and to reproduce the content of the NOTICE file.
13
+ ###
14
+ ### You may obtain a copy of the Apache License at
15
+ ###
16
+ ### http://www.apache.org/licenses/LICENSE-2.0
17
+ ###
18
+ ### Unless required by applicable law or agreed to in writing, software
19
+ ### distributed under the Apache License with the above modification is
20
+ ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21
+ ### KIND, either express or implied. See the Apache License for the specific
22
+ ### language governing permissions and limitations under the Apache License.
23
+ ###
24
+ ###
25
+
26
+ Chook.event_handler do |event|
27
+ eobject = event.event_object
28
+ whook = event.webhook
29
+
30
+ REPORT_ACTIONS = {
31
+ 'PUT' => 'update',
32
+ 'POST' => 'create',
33
+ 'DELETE' => 'delete'
34
+ }.freeze unless defined? REPORT_ACTIONS
35
+
36
+ action = REPORT_ACTIONS[eobject.restAPIOperationType]
37
+
38
+ return nil unless action
39
+
40
+ puts <<-ENDMSG
41
+ The JSS WebHook named '#{whook.name}' was just triggered.
42
+ It indicates that Casper user '#{eobject.authorizedUsername}' just used the JSS API to #{action}
43
+ the JSS #{eobject.objectTypeName} named '#{eobject.objectName}' (id #{eobject.objectID})
44
+ ENDMSG
45
+ end
@@ -0,0 +1,47 @@
1
+ #!/bin/bash
2
+ ### Copyright 2017 Pixar
3
+ ###
4
+ ### Licensed under the Apache License, Version 2.0 (the "Apache License")
5
+ ### with the following modification; you may not use this file except in
6
+ ### compliance with the Apache License and the following modification to it:
7
+ ### Section 6. Trademarks. is deleted and replaced with:
8
+ ###
9
+ ### 6. Trademarks. This License does not grant permission to use the trade
10
+ ### names, trademarks, service marks, or product names of the Licensor
11
+ ### and its affiliates, except as required to comply with Section 4(c) of
12
+ ### the License and to reproduce the content of the NOTICE file.
13
+ ###
14
+ ### You may obtain a copy of the Apache License at
15
+ ###
16
+ ### http://www.apache.org/licenses/LICENSE-2.0
17
+ ###
18
+ ### Unless required by applicable law or agreed to in writing, software
19
+ ### distributed under the Apache License with the above modification is
20
+ ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21
+ ### KIND, either express or implied. See the Apache License for the specific
22
+ ### language governing permissions and limitations under the Apache License.
23
+ ###
24
+ ###
25
+
26
+ # NOTE: Native bash doesn't have any easy way to parse JSON.
27
+ # Instead, you should really use a tool like 'jq' https://stedolan.github.io/jq/.
28
+ #
29
+ # If you have jq, set its correct path in the JQ variable below.
30
+ #
31
+ # It's beyond the scope of this example to parse the JSON with regular expressions
32
+ # which is a horrible idea anyway.
33
+
34
+ # Enter your path to jq
35
+ JQ=/usr/local/bin/jq
36
+
37
+ HANDLER_NAME=`basename "$0"`
38
+ CHANGELOG='/tmp/smart-computer-group-changes.log'
39
+
40
+ # read all of stdin into a variable
41
+ while read line ; do JSON="$JSON $line" ; done
42
+ now=`date +'%Y-%m-%d %H:%M:%S'`
43
+ groupname=`echo $JSON | "$JQ" -r '.event.name'`
44
+
45
+ msg="$now $HANDLER_NAME: Smart Computer Group '$groupname' changed."
46
+
47
+ echo "$msg" >> "$CHANGELOG"
@@ -0,0 +1,33 @@
1
+ ### Copyright 2017 Pixar
2
+
3
+ ###
4
+ ### Licensed under the Apache License, Version 2.0 (the "Apache License")
5
+ ### with the following modification; you may not use this file except in
6
+ ### compliance with the Apache License and the following modification to it:
7
+ ### Section 6. Trademarks. is deleted and replaced with:
8
+ ###
9
+ ### 6. Trademarks. This License does not grant permission to use the trade
10
+ ### names, trademarks, service marks, or product names of the Licensor
11
+ ### and its affiliates, except as required to comply with Section 4(c) of
12
+ ### the License and to reproduce the content of the NOTICE file.
13
+ ###
14
+ ### You may obtain a copy of the Apache License at
15
+ ###
16
+ ### http://www.apache.org/licenses/LICENSE-2.0
17
+ ###
18
+ ### Unless required by applicable law or agreed to in writing, software
19
+ ### distributed under the Apache License with the above modification is
20
+ ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21
+ ### KIND, either express or implied. See the Apache License for the specific
22
+ ### language governing permissions and limitations under the Apache License.
23
+ ###
24
+ ###
25
+
26
+ HANDLER_NAME = File.basename __FILE__
27
+ CHANGELOG = '/tmp/smart-computer-group-changes.log'.freeze
28
+
29
+ Chook.event_handler do |event|
30
+ now = Time.now.strftime '%Y-%m-%d %H:%M:%S'
31
+ msg = "#{now} #{HANDLER_NAME}: Smart Computer Group '#{event.event_object.name}' changed.\n"
32
+ open(CHANGELOG, 'a') { |file| file.write msg }
33
+ end
@@ -0,0 +1,27 @@
1
+ {
2
+ "webhook": {
3
+ "id": 1,
4
+ "name": "ComputerAdded Webhook",
5
+ "webhookEvent": "ComputerAdded"
6
+ },
7
+ "event": {
8
+ "udid": "99848AF0-xxxx-XXXX-xxxx-B79B9F65D7F8",
9
+ "deviceName": "wanderer",
10
+ "model": "MacBookPro10,1",
11
+ "macAddress": "yy:E0:yy:16:yy:E9",
12
+ "alternateMacAddress": "32:xx:1A:xx:xx:60",
13
+ "serialNumber": "VM87S764H831",
14
+ "osVersion": "10.15.2",
15
+ "osBuild": "48673",
16
+ "userDirectoryID": "-1",
17
+ "username": "username",
18
+ "realName": "User Name",
19
+ "emailAddress": "user@school.edu",
20
+ "phone": "x3369",
21
+ "position": "Apple Peeler",
22
+ "department": "MacBack",
23
+ "building": "Soho",
24
+ "room": "s167",
25
+ "jssID": 1322
26
+ }
27
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "webhook": {
3
+ "id": 2,
4
+ "name": "ComputerCheckin Webhook",
5
+ "webhookEvent": "ComputerCheckin"
6
+ },
7
+ "event": {
8
+ "udid": "99848AF0-xxxx-XXXX-xxxx-B79B9F65D7F8",
9
+ "deviceName": "wanderer",
10
+ "model": "MacBookPro10,1",
11
+ "macAddress": "yy:E0:yy:16:yy:E9",
12
+ "alternateMacAddress": "32:xx:1A:xx:xx:60",
13
+ "serialNumber": "VM87S764H831",
14
+ "osVersion": "10.15.2",
15
+ "osBuild": "48673",
16
+ "userDirectoryID": "-1",
17
+ "username": "username",
18
+ "realName": "User Name",
19
+ "emailAddress": "user@school.edu",
20
+ "phone": "x3369",
21
+ "position": "Apple Peeler",
22
+ "department": "MacBack",
23
+ "building": "Soho",
24
+ "room": "s167",
25
+ "jssID": 1322
26
+ }
27
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "webhook": {
3
+ "id": 3,
4
+ "name": "ComputerInventoryCompleted Webhook",
5
+ "webhookEvent": "ComputerInventoryCompleted"
6
+ },
7
+ "event": {
8
+ "udid": "99848AF0-xxxx-XXXX-xxxx-B79B9F65D7F8",
9
+ "deviceName": "wanderer",
10
+ "model": "MacBookPro10,1",
11
+ "macAddress": "yy:E0:yy:16:yy:E9",
12
+ "alternateMacAddress": "32:xx:1A:xx:xx:60",
13
+ "serialNumber": "VM87S764H831",
14
+ "osVersion": "10.15.2",
15
+ "osBuild": "48673",
16
+ "userDirectoryID": "-1",
17
+ "username": "username",
18
+ "realName": "User Name",
19
+ "emailAddress": "user@school.edu",
20
+ "phone": "x3369",
21
+ "position": "Apple Peeler",
22
+ "department": "MacBack",
23
+ "building": "Soho",
24
+ "room": "s167",
25
+ "jssID": 1322
26
+ }
27
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "webhook": {
3
+ "id": 4,
4
+ "name": "ComputerPolicyFinished Webhook",
5
+ "webhookEvent": "ComputerPolicyFinished"
6
+ },
7
+ "event": {
8
+ "udid": "99848AF0-xxxx-XXXX-xxxx-B79B9F65D7F8",
9
+ "deviceName": "wanderer",
10
+ "model": "MacBookPro10,1",
11
+ "macAddress": "yy:E0:yy:16:yy:E9",
12
+ "alternateMacAddress": "32:xx:1A:xx:xx:60",
13
+ "serialNumber": "VM87S764H831",
14
+ "osVersion": "10.15.2",
15
+ "osBuild": "48673",
16
+ "userDirectoryID": "-1",
17
+ "username": "username",
18
+ "realName": "User Name",
19
+ "emailAddress": "user@school.edu",
20
+ "phone": "x3369",
21
+ "position": "Apple Peeler",
22
+ "department": "MacBack",
23
+ "building": "Soho",
24
+ "room": "s167",
25
+ "jssID": 1322
26
+ }
27
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "webhook": {
3
+ "id": 5,
4
+ "name": "ComputerPushCapabilityChanged Webhook",
5
+ "webhookEvent": "ComputerPushCapabilityChanged"
6
+ },
7
+ "event": {
8
+ "udid": "99848AF0-xxxx-XXXX-xxxx-B79B9F65D7F8",
9
+ "deviceName": "wanderer",
10
+ "model": "MacBookPro10,1",
11
+ "macAddress": "yy:E0:yy:16:yy:E9",
12
+ "alternateMacAddress": "32:xx:1A:xx:xx:60",
13
+ "serialNumber": "VM87S764H831",
14
+ "osVersion": "10.15.2",
15
+ "osBuild": "48673",
16
+ "userDirectoryID": "-1",
17
+ "username": "username",
18
+ "realName": "User Name",
19
+ "emailAddress": "user@school.edu",
20
+ "phone": "x3369",
21
+ "position": "Apple Peeler",
22
+ "department": "MacBack",
23
+ "building": "Soho",
24
+ "room": "s167",
25
+ "jssID": 1322
26
+ }
27
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "webhook": {
3
+ "id": 7,
4
+ "name": "JSSShutdown Webhook",
5
+ "webhookEvent": "JSSShutdown"
6
+ },
7
+ "event": {
8
+ "institution": "MyCoolSchool",
9
+ "hostAddress": "casper.mycoolschool.edu",
10
+ "webApplicationPath": "/path/to/web/app",
11
+ "isClusterMaster": true,
12
+ "jssUrl": "https://casper.mycoolschool.edu:8443/"
13
+ }
14
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "webhook": {
3
+ "id": 8,
4
+ "name": "JSSStartup Webhook",
5
+ "webhookEvent": "JSSStartup"
6
+ },
7
+ "event": {
8
+ "institution": "MyCoolSchool",
9
+ "hostAddress": "casper.mycoolschool.edu",
10
+ "webApplicationPath": "/path/to/web/app",
11
+ "isClusterMaster": true,
12
+ "jssUrl": "https://casper.mycoolschool.edu:8443/"
13
+ }
14
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "webhook": {
3
+ "id": 9,
4
+ "name": "MobileCheckin Webhook",
5
+ "webhookEvent": "MobileDeviceCheckIn"
6
+ },
7
+ "event": {
8
+ "udid": "0d12c74062dxyxyxb4b234f4ac1yxyxyx1efccd0",
9
+ "deviceName": "tipple",
10
+ "version": "4.71.00",
11
+ "model": "iPhone7,2",
12
+ "bluetoothMacAddress": "xx:xx:37:yy:78:xx",
13
+ "wifiMacAddress": "yy:yy:37:xx:78:yy",
14
+ "imei": "xx yyyyyy zzzzzz 0",
15
+ "icciID": "aaaa bbbb cccc dddd eeee",
16
+ "product": null,
17
+ "serialNumber": "C8EM25KSG5PT",
18
+ "userDirectoryID": "-1",
19
+ "room": "s167",
20
+ "osVersion": "9.3.4",
21
+ "osBuild": "13G35",
22
+ "modelDisplay": "iPhone 6",
23
+ "username": "username",
24
+ "jssID": 158
25
+ }
26
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "webhook": {
3
+ "id": 10,
4
+ "name": "MobileCommandComplete Webhook",
5
+ "webhookEvent": "MobileDeviceCommandCompleted"
6
+ },
7
+ "event": {
8
+ "udid": "0d12c74062dxyxyxb4b234f4ac1yxyxyx1efccd0",
9
+ "deviceName": "tipple",
10
+ "version": "4.71.00",
11
+ "model": "iPhone7,2",
12
+ "bluetoothMacAddress": "xx:xx:37:yy:78:xx",
13
+ "wifiMacAddress": "yy:yy:37:xx:78:yy",
14
+ "imei": "xx yyyyyy zzzzzz 0",
15
+ "icciID": "aaaa bbbb cccc dddd eeee",
16
+ "product": null,
17
+ "serialNumber": "C8EM25KSG5PT",
18
+ "userDirectoryID": "-1",
19
+ "room": "s167",
20
+ "osVersion": "9.3.4",
21
+ "osBuild": "13G35",
22
+ "modelDisplay": "iPhone 6",
23
+ "username": "username",
24
+ "jssID": 158
25
+ }
26
+ }