async function sendGPOPackageNotification()

in functions/GPOPackagesFunction/index.js [27:79]


async function sendGPOPackageNotification() {
  try {
    const failureSent = false; //await wasFailureSent();
    // if a previous failure message was sent, exit out
    // this is to prevent sending multiple failure messages
    if (failureSent) {
      return;
    }

    const currentPkg = await getCurrentPackageSSM();
    const searchDate = await getSearchDate(currentPkg);
    const packageFound = await checkForNewPackage(searchDate);

    // if the current date is on of after the search date, check for a new GPO package
    if (Date.now() >= searchDate) {
      // create SNS notification for when a new package is found
      let snsParams = {
        Message: `A new DISA STIG GPO package is available for download on the DISA website. 
                  It is highly recommended that you download this package and upload it to the S3 bucket so the GPOs just be installed/updated in Active Directory.\n 
                  Link to GPO package: https://${disa.DownloadBaseUrl}${disa.PackagePath}${pkgFileName}.zip\n
                  Link to DISA STIGs: ${disa.GPOWebsiteUrl}`,
        Subject: "New DISA STIG GPO package available for download",
        TopicArn: topicArn,
      };

      if (!packageFound) {
        let alertDate = searchDate;
        alertDate.setDate(7);

        // if a new package was not found and it is at least a week into the month, send a failure notification
        if (Date.now() >= alertDate) {
          // set the SNS message and subject for the failure notification
          snsParams = {
            Message: `A new DISA STIG GPO package was not found on the DISA website but should be available by now. It is highly recommend to go to the 
                    DISA website and see if a package is available or further information about a release date is posted.\n
                    Link to DISA STIGs: ${disa.GPOWebsiteUrl}`,
            Subject:
              "A New DISA STIG GPO package was not found on the DISA website",
            TopicArn: topicArn,
          };

          // update the SSM parameter identifying that a failure message was sent
          await updateFailureSSM("true");
        }
      }

      // publish message to the SNS topic
      await sns.publish(snsParams).promise();
    }
  } catch (error) {
    console.log(error);
  }
}