var repl = JSON.parse(value).Replication;
var res = Object.keys(repl)
    .filter(function (v) {return v.match(/slave\d+/)})
    .filter(function (v) {return (repl[v].ip === "{#SLAVE_IP}" && repl[v].port === "{#SLAVE_PORT}")})
    .map(function (v) {return repl[v].offset})[0];

if (res === undefined) {
    throw 'Slave {#SLAVE_IP}:{#SLAVE_PORT} is no longer available.';
}

return res;