{"id":1317,"date":"2023-07-17T23:06:01","date_gmt":"2023-07-17T15:06:01","guid":{"rendered":"https:\/\/rain1024.com\/?p=1317"},"modified":"2023-08-07T21:00:29","modified_gmt":"2023-08-07T13:00:29","slug":"1317","status":"publish","type":"post","link":"http:\/\/rain1024.com\/index.php\/2023\/07\/17\/1317\/","title":{"rendered":"\u7b80\u6613\u6ce8\u518c\u4e2d\u5fc3\u76d1\u63a7NAS\u65ad\u7535\u65ad\u7f51"},"content":{"rendered":"<p>\u65e5\u5e38\u4f7f\u7528NAS\u8fc7\u7a0b\u4e2d\uff0c\u5076\u5c14\u4f1a\u51fa\u73b0\u5bb6\u91cc\u65ad\u7535\u6216\u8005\u65ad\u7f51\u7684\u60c5\u51b5\uff0cNAS\u81ea\u5e26\u7f51\u7edc\u65ad\u5f00\u7684\u901a\u77e5\u529f\u80fd\uff0c\u4f46\u9700\u8981\u662f\u6062\u590d\u7f51\u7edc\u94fe\u63a5\u540e\u624d\u4f1a\u901a\u77e5\uff0c\u800c\u6b64\u65f6\u90fd\u6062\u590d\u4e86\uff0c\u518d\u901a\u77e5\u4e5f\u5c31\u6ca1\u90a3\u4e48\u91cd\u8981\uff0c\u8fd8\u6709\u65ad\u7535\u60c5\u51b5\u4e0b\u4e5f\u662f\u9700\u8981\u56de\u5bb6\u624d\u80fd\u77e5\u9053\uff0c\u65ad\u7535\u4fdd\u62a4\u53ef\u4ee5\u4f7f\u7528UPS\uff0c\u5f53\u505c\u7535\u540eUPS\u901a\u8fc7usb\u6570\u636e\u7ebf\u4f1a\u7ed9NAS\u53d1\u9001\u901a\u77e5\uff0cNAS\u6536\u5230\u901a\u77e5\u540e\u5728\u8bbe\u5b9a\u65f6\u95f4\u5185\u5173\u673a\u5e76\u53d1\u9001ups\u8fdb\u5165\u7535\u6c60\u4f9b\u7535\u6a21\u5f0f\u7684\u901a\u77e5\uff0c\u4f46\u8fd9\u4e2a\u65b9\u5f0f\u9700\u8981\u8d2d\u4e70ups\u8bbe\u5907\uff0c\u6210\u672c\u5728300\u5143\u5de6\u53f3\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rain1024.com\/wp-content\/uploads\/2023\/07\/post-1317-64b558d975f0a.png\" alt=\"\" \/><\/p>\n<h3>\u6ce8\u518c\u4e2d\u5fc3\u539f\u7406<\/h3>\n<p>\u8054\u60f3\u5230\u6ce8\u518c\u4e2d\u5fc3\u7b49\u5176\u4ed6\u96c6\u7fa4\u6a21\u5f0f\u4e0b\u7684\u5fc3\u8df3\u8fde\u63a5\uff0c\u5fc3\u8df3\u8d85\u65f6\u5219\u8fdb\u884c\u5254\u9664\u7684\u65b9\u5f0f\uff0c\u81ea\u5df1\u4fbf\u7528python\u5199\u4e86\u4e00\u4e2a\u7b80\u5355\u7684web\u670d\u52a1\u5f53\u4f5c\u6ce8\u518c\u4e2d\u5fc3\uff0c\u518d\u5199\u4e00\u4e2a\u5b9a\u65f6\u4efb\u52a1\u6bcf\u96945\u79d2\u626b\u63cf\u4e00\u904d\u6700\u8fd1\u6ce8\u518c\u65f6\u95f4\u6570\u636e\uff0c\u5bf9\u6bd4\u4e0b\u6765\u5982\u679c\u8d85\u65f660\u79d2\u4ee5\u4e0a\uff0c\u5219\u8ba4\u4e3aNAS\u5df2\u7ecf\u5931\u53bb\u94fe\u63a5\uff0c\u7acb\u523b\u53d1\u9001\u90ae\u4ef6\/\u9489\u9489\u901a\u77e5\uff0c\u5f53NAS\u91cd\u65b0\u4e0a\u7ebf\u8fde\u63a5\u540e\uff0c\u5b9a\u65f6\u4efb\u52a1\u626b\u63cf\u5230\u6ce8\u518c\u4fe1\u606f\u4f1a\u518d\u53d1\u9001\u5df2\u7ecf\u8fde\u63a5\u7684\u901a\u77e5\u4fe1\u606f\u3002<\/p>\n<h3>NAS\u7aef\u539f\u7406<\/h3>\n<p>\u4e0a\u6587\u5df2\u7ecf\u901a\u8fc7python\u63d0\u4f9b\u4e86\u4e00\u4e2aweb\u670d\u52a1\uff0c\u6b64\u65f6\u53ea\u9700\u8981\u5728NAS\u7aef\u4efb\u52a1\u8ba1\u5212\u4e2d\u521b\u5efa\u4e00\u4e2a\u6bcf\u5206\u949f\u7684\u5b9a\u65f6\u4efb\u52a1\u5373\u53ef\uff0c\u5b9a\u65f6\u8bf7\u6c42\u5fc3\u8df3\u63a5\u53e3\uff0c\u670d\u52a1\u7aef\u8bb0\u5f55\u8bf7\u6c42\u65f6\u95f4\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rain1024.com\/wp-content\/uploads\/2023\/07\/post-1317-64b558d9c1336.png\" alt=\"\" \/><\/p>\n<p>\u6216\u8005\u5728docker\u91cc\u542f\u52a8\u4e00\u4e2a\u5b9a\u65f6\u4efb\u52a1\uff0ccrontab\u547d\u4ee4<\/p>\n<pre><code>service cron start\n*\/1 * * * * curl http:\/\/ip:2580\/register                            <\/code><\/pre>\n<h3>\u670d\u52a1\u7aef\u4ee3\u7801<\/h3>\n<p>\u542f\u52a8python\u7684\u547d\u4ee4\uff0c\u9700\u8981\u5728\u540e\u53f0\u8fd0\u884c<\/p>\n<pre><code>ps -ef|grep python\nnohup python3 nas_health.py  &amp;\nnohup python3 nas_register.py  &amp;<\/code><\/pre>\n<p>nas_register-\u7c7b\u4f3c\u4e8e\u6ce8\u518c\u4e2d\u5fc3\u7684\u6982\u5ff5\uff0c\u63d0\u4f9b\u4e00\u4e2aget\u63a5\u53e3\u4f9bNAS\u8bbf\u95ee<\/p>\n<pre><code># -*- encoding: utf-8 -*-\nimport os\nimport datetime\nimport tornado.web\n\nclass MainHandler(tornado.web.RequestHandler):\n    def get(self):\n        &quot;&quot;&quot;get\u8bf7\u6c42&quot;&quot;&quot;\n        now = datetime.datetime.now()\n        out = open(&quot;nas_datetime-&quot; + str(now.year) + &#039;-&#039; + str(now.month) + &#039;-&#039; + str(now.day), &#039;a&#039;)\n        out.write(str(now) + &#039;\\n&#039;)\n        out.close()\n        self.write(&quot;&quot;)\n\napplication = tornado.web.Application([(r&quot;\/register&quot;, MainHandler)],\n                                      static_path=os.path.join(os.path.dirname(__file__), &quot;static&quot;), )\n\n# \u8bfb\u53d6\u6587\u4ef6\u4e2d\u7684\u6570\u636e\ndef read_txt_file(file_name):\n    newFile = open(file_name)\n    data = newFile.read()\n    newFile.close()\n    return data\n\nif __name__ == &quot;__main__&quot;:\n    application.listen(2580)\n    tornado.ioloop.IOLoop.instance().start()<\/code><\/pre>\n<p>nas_health-\u5b9a\u65f6\u626b\u63cf\u65e5\u5fd7\u6587\u4ef6\uff0c\u5bf9\u6bd4\u6ce8\u518c\u65f6\u95f4<\/p>\n<pre><code># -*- encoding: utf-8 -*-\nimport datetime\nimport time\nimport smtplib\nfrom email.mime.text import MIMEText\nfrom email.header import Header\n\n# \u8bfb\u53d6\u6587\u4ef6\u4e2d\u7684\u6570\u636e\ndef read_txt_file(file_name):\n    newFile = open(file_name)\n    data = newFile.read()\n    if data == &#039;&#039;:\n        return &#039;&#039;\n    now = &#039;&#039;\n    for line in data.split(&#039;\\n&#039;):\n        if line == &#039;&#039;:\n            break\n        now = line\n    newFile.close()\n    return now\n\ndef loop_monitor():\n    email_state = True\n    while True:\n        try:\n            file_now = datetime.datetime.now()\n            now_str = read_txt_file(\n                &quot;nas_datetime-&quot; + str(file_now.year) + &#039;-&#039; + str(file_now.month) + &#039;-&#039; + str(file_now.day))\n            if now_str == &#039;&#039;:\n                continue\n            now = datetime.datetime.strptime(str(now_str), &quot;%Y-%m-%d %H:%M:%S.%f&quot;)\n            now2 = datetime.datetime.now()\n            print((now2 - now).seconds)\n            if (now2 - now).seconds &gt;= 60 and email_state:\n                email(&quot;\u5fc3\u8df3\u5df2\u7ecf\u8d85\u65f6&quot;, &quot;xxx@xxx.com&quot;)\n                email_state = False\n            if (now2 - now).seconds &lt; 60 and email_state == False:\n                email_state = True\n                email(&quot;\u5fc3\u8df3\u5df2\u7ecf\u6062\u590d&quot;, &quot;xxx@xxx.com&quot;)\n        except Exception as e:\n            print(&quot;\u65f6\u95f4\u9519\u8bef&quot;, e)\n        time.sleep(5)  # \u6682\u505c5\u79d2\n\ndef email(text, toemail):\n    sender = &quot;xxx@xxx.com&quot;  # \u53d1\u9001\u65b9\u7684\u90ae\u7bb1\n    password = &quot;xxxx.&quot;  # \u90ae\u7bb1\u7684\u6388\u6743\u7801\n    receiver = toemail  # \u63a5\u6536\u65b9\u7684\u90ae\u7bb1\n    data_time = time.strftime(&quot;%Y-%m-%d %H:%M:%S&quot;)\n    subject = data_time + &quot;Nas\u670d\u52a1\u5668\u5fc3\u8df3\u62a5\u8b66&quot;  # title\u90ae\u4ef6\u6807\u9898\n    words = text  # text\u90ae\u4ef6\u5185\u5bb9\n    msg = MIMEText(words, &#039;plain&#039;, &#039;utf-8&#039;)  # \u4e2d\u6587\u9700\u53c2\u6570\u2018utf-8&#039;\uff0c\u5355\u5b57\u8282\u5b57\u7b26\u4e0d\u9700\u8981\n    msg[&#039;Subject&#039;] = Header(subject, &#039;utf-8&#039;)  # \u90ae\u4ef6\u6807\u9898\n    msg[&#039;from&#039;] = sender  # \u53d1\u4fe1\u4eba\u5730\u5740\n    msg[&#039;to&#039;] = receiver  # \u6536\u4fe1\u4eba\u5730\u5740\n    smtp = smtplib.SMTP_SSL(&quot;smtp.exmail.qq.com&quot;, 465)\n    smtp.connect(&#039;smtp.exmail.qq.com&#039;)\n    smtp.login(sender, password)\n    smtp.sendmail(sender, receiver, msg.as_string())\n    smtp.quit()\n\nif __name__ == &quot;__main__&quot;:\n    loop_monitor()<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/rain1024.com\/wp-content\/uploads\/2023\/07\/post-1317-64b558d9ef38a.png\" alt=\"\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u65e5\u5e38\u4f7f\u7528NAS\u8fc7\u7a0b\u4e2d\uff0c\u5076\u5c14\u4f1a\u51fa\u73b0\u5bb6\u91cc\u65ad\u7535\u6216\u8005\u65ad\u7f51\u7684\u60c5\u51b5\uff0cNAS\u81ea\u5e26\u7f51\u7edc\u65ad\u5f00\u7684\u901a\u77e5\u529f\u80fd\uff0c\u4f46\u9700\u8981\u662f\u6062\u590d\u7f51\u7edc\u94fe\u63a5\u540e\u624d\u2026 <span class=\"read-more\"><a href=\"http:\/\/rain1024.com\/index.php\/2023\/07\/17\/1317\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":1320,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,15],"tags":[],"class_list":["post-1317","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-other","category-python"],"_links":{"self":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/1317","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/comments?post=1317"}],"version-history":[{"count":2,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/1317\/revisions"}],"predecessor-version":[{"id":1319,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/1317\/revisions\/1319"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/media\/1320"}],"wp:attachment":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/media?parent=1317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/categories?post=1317"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/tags?post=1317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}