LINUX.ORG.RU

Написал в итоге такой велосипед, может пригодится кому:

function isObject(obj) {
  return typeof obj === "object" && obj !== null && !(obj instanceof Date) && !(obj instanceof NumberLong);
}

// @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries#Polyfill
function objectEntries(obj) {
  var ownProps = Object.keys(obj),
    i = ownProps.length,
    resArray = new Array(i); // preallocate the Array
  while (i--) resArray[i] = [ownProps[i], obj[ownProps[i]]];

  return resArray;
}

function flattenObject(obj, prefix = "") {
  let result = {};

  for ([key, value] of objectEntries(obj)) {
    const safeKey = key.replace(/\s+|_+/g, '_');
    const path = prefix ? `${prefix}.${safeKey}` : safeKey;


    if (isObject(value)) {
      result = Object.assign({}, result, flattenObject(value, path));
    } else if (value instanceof NumberLong) {
      result[path] = value.valueOf();
    } else {
      result[path] = value;
    }
  }

  return result;
}

(() => {
  const serverStatus = flattenObject(db.serverStatus(), 'mongodb');

  for ([key, value] of objectEntries(serverStatus)) {
    print(`- ${key} ${JSON.stringify(value)}`);
  }

  const replicationInfo = flattenObject(db.getReplicationInfo(), 'mongodb.getReplicationInfo');

  for ([key, value] of objectEntries(replicationInfo)) {
    print(`- ${key} ${JSON.stringify(value)}`);
  }

  const replicaSetStatus = flattenObject(db.adminCommand({replSetGetStatus: 1}), 'mongodb.replSetGetStatus');

  for ([key, value] of objectEntries(replicaSetStatus)) {
    print(`- ${key} ${JSON.stringify(value)}`);
  }
})();

Запускать прям из mongodb, отсылать через zabbix_sender:

mongo script_name.js
ostin ★★★★★ ()