Crypto Mining SMS Alerts

27 Dec 2023

Time is money in the world of crypto mining. Operating different miners with flaky app alerts can lead to unnoticed failures that need immediate attention. In this example from our community we will monitor rigs from Nicehash and use the SBMG developer API forming a python script to alert us via SMS when a rig is offline.

SMS

Our script uses the SBMG API to send SMS alerts. The sendSms function is the cornerstone of this alert system. Here's how it works:

# CONFIG
# SBMG
sbmg_api_key = 'Get your api key at portal.sbmg.app/settings#api'
sbmg_url = "https://api.sbmg.app/sms"

# Send an sms alert with SBMG
def sendSms(rigName):
    payload = json.dumps({
        "to": [
            "+6422987123"  # Replace with your phone number
        ],
        "message": f"ALERT!\nProcess error detected on server {rigName}."
    })
    headers = {
    'x-api-key': sbmg_api_key,
    'Content-Type': 'application/json'
    }
    response = requests.request("POST", sbmg_url, headers=headers, data=payload)
    print(response.text)
  • Payload Configuration: The function constructs a payload with your phone number and a custom message. This message contains the name of the rig that has encountered an issue, providing you with specific and actionable information.

  • Security Practices: Ensure that your SBMG API key is stored securely. As with any sensitive data, it's vital to protect this key from unauthorized access.

  • Customizing Messages: While the default message format is provided, you can customize it according to your preferences. For example, you might want to include additional details like the time of the alert or the specific error detected

Monitoring Process

In the fast-paced world of cryptocurrency mining, staying informed about the status of your mining rigs is crucial. A rig going offline can mean a significant loss in potential earnings. This section guides you through setting up an automated system that keeps you updated on the status of your rigs.

Before we dive into the code, let's understand Nicehash. Nicehash is a popular platform that allows users to buy and sell computing power for mining cryptocurrencies. Our script will interact with the Nicehash API to retrieve real-time data about your mining rigs. We can install Nicehash's python module with the pip command below:

pip install nicehash

First and foremost, you need to generate your API credentials from Nicehash as instructed in Nicehash's guide here. These credentials are the gateway to fetching data from your Nicehash account. It's crucial to handle these credentials securely. Never share your API key or secret, and avoid hardcoding them directly into your scripts. Instead, consider using environment variables or a secure method to store these credentials. For our example we can add our api credentials to our script as below:

# CONFIG
# Nicehash
api_key = 'YOUR_API_KEY'
api_secret = 'YOUR_API_SECRET'
organization_id = 'YOUR_ORG_ID'
nicehash_host = 'https://api2.nicehash.com'
expected_active_rigs = 3  # Set your total active rig count
# SBMG

Once you have your Nicehash API credentials, the script will periodically query the status of your mining rigs. The goal is to identify any rigs that are not actively mining. This could be due to various issues, such as hardware malfunctions, network problems, or power outages. Early detection of these inactive rigs is vital to minimize downtime and maintain optimal mining operations.

The script is designed to send an SMS alert whenever it detects an inactive rig. This immediate notification allows you to take swift action to rectify the issue. You can customize the alert system to include more details or to integrate with other notification methods, depending on your preference.

from nicehash import nicehash

# Setup Nicehash client
client = nicehash.private_api(nicehash_host, organization_id, api_key, api_secret)

while True:
    # Fetch rig information
    rigs = client.get_rigs()

    # Check for inactive rigs
    if rigs['minerStatuses']['MINING'] == expected_active_rigs:
        print("All rigs are mining")
    else:
        for rig in rigs['miningRigs']:
            if rig['minerStatus'] != 'MINING':
                rig_name = rig['rigId']
                print(f'{rig_name} is offline')
                sendSms(rig['rigId'])

    time.sleep(60*60)  # Sleep in seconds (60*60 is 60 minutes)

Running the complete script we now have periodic monitoring of rig states.

Conclusion

With a process like this you'll have a functional, automated monitoring system that keeps you informed about the status of your mining rigs. This system not only saves time but also acts as an essential component in maximising your mining efficiency and profitability.

While this guide focuses on Nicehash, the concept is versatile and can be adapted to other mining platforms. The principles of monitoring and alerting are universal in mining operations. With minor adjustments to the API interaction, this script can be a valuable tool for various mining environments. Similarly it isn't restricted to Nicehash, a monitoring process could be applied to other mining platforms and even outside mining sms is a high reach alerting method for any other services you need to monitor and can easily be applied here too.

Disclaimer

Not a Financial Endorsement: The content provided in this article, including the use of Nicehash and other crypto mining services, is for informational purposes only and is not intended as an endorsement of any specific cryptocurrency, mining service, or investment strategy. Cryptocurrency investments are subject to high market risks, including volatility and regulatory changes.

Security and Privacy Considerations: When using APIs and handling sensitive information like API keys and personal phone numbers for SMS alerts, it's crucial to prioritize security and privacy. Always ensure that your API keys are stored securely and not exposed in your scripts or to third parties.

Financial Risks in Crypto Mining: Be aware that crypto mining involves significant financial risks. These risks include potential losses due to hardware failure, fluctuating cryptocurrency values, and changes in mining difficulty. Energy costs associated with mining can also impact profitability.

Regulatory Compliance: Cryptocurrency mining and trading are subject to varying regulations in different jurisdictions. It's important to stay informed about and comply with all relevant laws and regulations in your region.

Responsibility of Monitoring: While automated monitoring systems can enhance efficiency and reduce the likelihood of unnoticed downtime, they are not foolproof. Continuous personal oversight and verification are recommended to ensure the accuracy and effectiveness of these systems.

Changes in Technology: The cryptocurrency market is dynamic, with frequent changes in technology, platforms, and best practices. The information presented in this article is based on the current state of technology and market conditions and may become outdated as new developments emerge.

Consultation with Professionals: For financial advice, investment strategies, or legal compliance, always consult with a qualified professional. Do not base significant investment or legal decisions solely on the information presented in this article.

Limitation of Liability: The author and publisher of this article are not liable for any losses or damages that may arise from the application of the information provided. Users are responsible for their own investment and security decisions.

By acknowledging these risks and responsibilities, you can make more informed decisions in your crypto mining ventures.

© Jungle Drum 2023