ktg5 / discord-uptimerobot

A Discord bot that uses UptimeRobot to detect if a service is down or not.
GNU General Public License v3.0
11 stars 6 forks source link

Malformed JSON in file data/db.json #5

Closed Wh1t3Rose closed 3 years ago

Wh1t3Rose commented 3 years ago

I am trying to add multiple monitors to db.json and keep getting json parse errors. No offense but either your app has a bug or the documentation needs updating. I copied lines 3-7 just like it says.

I think it would help if you updated your example file with multiple Monitors,

/scripts/discord-uptimerobot/node_modules/lowdb/adapters/FileSync.js:42
          throw e;
          ^

SyntaxError: Malformed JSON in file: data/db.json
Unexpected token { in JSON at position 129
    at FileSync.parse [as deserialize] (<anonymous>)
    at FileSync.read (/scripts/discord-uptimerobot/node_modules/lowdb/adapters/FileSync.js:37:30)
    at LodashWrapper.db.read (/scripts/discord-uptimerobot/node_modules/lowdb/lib/main.js:32:21)
    at module.exports (/scripts/discord-uptimerobot/node_modules/lowdb/lib/main.js:51:13)
    at Object.dbInit (/scripts/discord-uptimerobot/custom-modules/database.js:8:14)
    at Object.<anonymous> (/scripts/discord-uptimerobot/bot.js:13:21)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:14)
[nodemon] app crashed - waiting for file changes before starting...
{
  "monitors": [
    {
      "name": "Ombi",
      "value": "78884xxxx",
      "stopped": false
    }
    {
      "name": "Plex",
      "value": "78884xxx",
      "stopped": false
    }
 ]
}
Wh1t3Rose commented 3 years ago

Also your line numbers for the Service file in the Readme are way off. I guess the file changed a bit after you made the readme? Can you update the readme file with the proper line numbers? I think I got it right but want to be sure. Thanks!

ktg5 commented 3 years ago

JSON files require you to put , at the need of a new list.

So at line 7, add a , after the }.

Wh1t3Rose commented 3 years ago

Ok I got that fixed. Thank you. Can you please help with my service file. I am so close to getting this working. The bot works AND I can do /service SERVICENAME and it gives a response.

But I still only have one thing listed by the bot when I do /service in Discord and it lists the Example despite me renaming the case name for that section.

I have 2 sections below. Not sure If I copied the right lines as I think your ReadMe is out of date or doesn't list the right line numbers

    await cl.getMonitors({customUptimeRatio: [1, 7, 30]}).then((res) => {
      switch (args[1]) {
        case `Ombi`:
          // Example monitor
          // 
          // Monitors are defined in "data/db.json", for every monitor -- there should be another list in the collection.
          // See the README.md for more information.
          var monitor = botTools.findMonitor(res, monitorlist[0].value);
          var monitStatus = botTools.monitorStatus(monitor.status);
          var monitColor = botTools.embedColor(monitor.status);
          var emojiStatus = botTools.emojiMsg(monitor.status);
          var monitType = botTools.monitorType(monitor.port, monitor.type);

          var embed = new Discord.MessageEmbed()
            .setTitle(`${emojiStatus} ${monitor.friendlyname}`)
            .addField(`Type:`, monitType)
            .addField(`URL:`, monitor.url)
            .addField(`Status:`, monitStatus)
            .addField(`Today's uptime percentage:`, `${monitor.customuptimeratio[0]}%`)
            .setFooter(`Uptime detection by UptimeRobot.`)
            .setColor(monitColor)
          channelmsg.send({embed});

          logger.info(`----------------------------------------------`)
          logger.info(`${monitor.friendlyname} was tested by ${usernameMSG} on ${guildmsg.name}.`)
          logger.info(`Status: ${monitStatus} | Today's uptime %: ${monitor.customuptimeratio[0]}`)
        break;
        case `Plex`:
          // Example monitor
          // 
          // Monitors are defined in "data/db.json", for every monitor -- there should be another list in the collection.
          // See the README.md for more information.
          var monitor = botTools.findMonitor(res, monitorlist[1].value);
          var monitStatus = botTools.monitorStatus(monitor.status);
          var monitColor = botTools.embedColor(monitor.status);
          var emojiStatus = botTools.emojiMsg(monitor.status);
          var monitType = botTools.monitorType(monitor.port, monitor.type);

          var embed = new Discord.MessageEmbed()
            .setTitle(`${emojiStatus} ${monitor.friendlyname}`)
            .addField(`Type:`, monitType)
            .addField(`URL:`, monitor.url)
            .addField(`Status:`, monitStatus)
            .addField(`Today's uptime percentage:`, `${monitor.customuptimeratio[0]}%`)
            .setFooter(`Uptime detection by UptimeRobot.`)
            .setColor(monitColor)
          channelmsg.send({embed});

          logger.info(`----------------------------------------------`)
          logger.info(`${monitor.friendlyname} was tested by ${usernameMSG} on ${guildmsg.name}.`)
          logger.info(`Status: ${monitStatus} | Today's uptime %: ${monitor.customuptimeratio[0]}`)
        break;
        default:
          var embed = new Discord.MessageEmbed()
            .setTitle(`Please select your monitor you'd like to check on.`)
            .addField(`\`${prefix}service example\``, `Example monitor.`)
ktg5 commented 3 years ago

Please join the support server (Discord) for that type of help.