Last active
March 22, 2017 10:34
-
-
Save pmauduit/ff0706c0483770d5186e5c3792b48819 to your computer and use it in GitHub Desktop.
sodexo-prometheus-exporter
This file contains hidden or 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
FROM groovy:jre8-alpine | |
COPY sodexo.groovy / | |
# Needed for groovy versions < 2.5 (which is not released yet) | |
USER root | |
RUN rm -f /opt/groovy/lib/servlet-api-2.4.jar | |
USER groovy | |
CMD ["groovy", "/sodexo.groovy"] | |
This file contains hidden or 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 groovy | |
@Grapes([ | |
@Grab(group='com.squareup.okhttp3', module='okhttp', version='3.6.0'), | |
@Grab(group='com.sparkjava', module='spark-core', version='2.5.5'), | |
@Grab(group='javax.servlet', module='javax.servlet-api', version='3.1.0'), | |
@GrabExclude(group = 'javax.servlet', module='servlet-api'), | |
]) | |
import okhttp3.OkHttpClient | |
import okhttp3.Request | |
import okhttp3.Response | |
import static spark.Spark.* | |
// Etat du traffic: | |
// https://sodexo-technolac.votreextranet.com/static-portlet.cfm?id=WG361&zr=56 | |
// Menu: | |
// https://sodexo-technolac.votreextranet.com/iframeRestauration.cfm?zr=56 | |
def getSodexoQueueStatus() { | |
def httpclient = new OkHttpClient() | |
def req = new Request.Builder() | |
.url("https://sodexo-technolac.votreextranet.com/static-portlet.cfm?id=WG361&zr=56") | |
.build() | |
def response = httpclient.newCall(req).execute() | |
def body = response.body().string() | |
if (body.contains("https://sodexo-technolac.votreextranet.com/images/static/wg361/360/fluidite-o.png")) { | |
return 1 | |
} else if (body.contains("https://sodexo-technolac.votreextranet.com/images/static/wg361/360/fluidite-r.png")) { | |
return 2 | |
} else if (body.contains("https://sodexo-technolac.votreextranet.com/images/static/wg361/360/fluidite-v.png")) { | |
return 0 | |
} else { | |
return -1 | |
} | |
} | |
port(9103) | |
get "/*", { request, response -> "sodexo_queue_status{} ${getSodexoQueueStatus()}\n" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment