From 8c7dde25038edf6300814ed7a0b48741e4e8e557 Mon Sep 17 00:00:00 2001 From: mfrais <119472921+mfrais@users.noreply.github.com> Date: Tue, 9 Jan 2024 22:05:30 +0700 Subject: [PATCH] update script --- devi.sh | 28 +++++ monitor-devi.py | 84 ++++++++++++++ monitor-freya.py | 224 ++++++++++++++++++++++++++++++++++++++ monitor-lala.py | 84 ++++++++++++++ monitor.py | 18 ++- monitoring/ashel.txt | 7 -- monitoring/calysta.txt | 7 -- monitoring/collection.txt | 7 -- monitoring/devi.py | 17 +++ monitoring/devi.txt | 7 -- monitoring/eve.txt | 7 -- monitoring/freya.txt | 7 -- monitoring/haerin.txt | 7 -- monitoring/hanni.txt | 7 -- monitoring/hyein.txt | 7 -- monitoring/lina.txt | 7 -- monitoring/noella.txt | 7 -- monitoring/testc.py | 22 ++++ monitoring/util.py | 98 +++++++++++++++-- monitoring/wista.txt | 7 -- monitoring/yuvia.txt | 7 -- start.sh | 172 +++++++++++++++++++++++++---- 22 files changed, 718 insertions(+), 120 deletions(-) create mode 100755 devi.sh create mode 100644 monitor-devi.py create mode 100644 monitor-freya.py create mode 100644 monitor-lala.py delete mode 100644 monitoring/ashel.txt delete mode 100644 monitoring/calysta.txt delete mode 100644 monitoring/collection.txt create mode 100755 monitoring/devi.py delete mode 100644 monitoring/devi.txt delete mode 100644 monitoring/eve.txt delete mode 100644 monitoring/freya.txt delete mode 100644 monitoring/haerin.txt delete mode 100644 monitoring/hanni.txt delete mode 100644 monitoring/hyein.txt delete mode 100644 monitoring/lina.txt delete mode 100644 monitoring/noella.txt create mode 100644 monitoring/testc.py delete mode 100644 monitoring/wista.txt delete mode 100644 monitoring/yuvia.txt diff --git a/devi.sh b/devi.sh new file mode 100755 index 0000000..59d9a52 --- /dev/null +++ b/devi.sh @@ -0,0 +1,28 @@ +#!/usr/bin/expect -f +set path [lindex $argv 0] +set date [lindex $argv 1] + +#Lala +spawn ssh -p4848 ditolak@lala.cayangqu.com python3.8 './twitmonitor/monitor.py' $path $date +expect "password:" +send "2020 Rahasia123!\r" +interact +sleep 2 +spawn scp -P4848 ditolak@lala.cayangqu.com:/home/ditolak/twitmonitor/twit_monitor.txt ./monitoring/lala.txt +expect "password:" +send "2020 Rahasia123!\r" +interact + +#Anin +spawn ssh -p4848 biasa@anin.cayangqu.com python3.8 './twitmonitor/monitor.py' $path $date +expect "password:" +send "2020 seperti kemarin\r" +interact +sleep 2 +spawn scp -P4848 biasa@anin.cayangqu.com:/home/biasa/twitmonitor/twit_monitor.txt ./monitoring/anin.txt +expect "password:" +send "2020 seperti kemarin\r" +interact + +spawn ./monitoring/devi.py +interact \ No newline at end of file diff --git a/monitor-devi.py b/monitor-devi.py new file mode 100644 index 0000000..be057a5 --- /dev/null +++ b/monitor-devi.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 +import subprocess +import datetime +import json +import sys + +now = datetime.datetime.now() +date = now.strftime('%Y%m%d') + +server_name = 'devi.cayangqu.com' + +try: + nama_log = f"auto_replytoaccNretweet.log.{sys.argv[2]}" +except: + nama_log = "auto_replytoaccNretweet.log" + +def twit_sent(): + ls_process = subprocess.Popen(["cat",f"/home/bsmqris/buzz/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "twit sent with text"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = wc_process.communicate() + return f"Twit sent: {output}" + +def twit_failed(): + ls_process = subprocess.Popen(["cat",f"/home/bsmqris/buzz/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "twit failed"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = wc_process.communicate() + return f"Twit failed: {output}" + +def quote_tweet(): + ls_process = subprocess.Popen(["cat",f"/home/bsmqris/buzz/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "quote twit sent"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = wc_process.communicate() + return f"Twit quoted: {output}" + +def reply_tweet(): + ls_process = subprocess.Popen(["cat",f"/home/bsmqris/buzz/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "reply twit sent"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = wc_process.communicate() + return f"Twit replied: {output}" + +def twit_failed2(): + with open(f"/home/bsmqris/twitmonitor/twit_failed.txt", 'w') as f: + ls_process = subprocess.Popen(["cat",f"/home/bsmqris/buzz/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "twit failed"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = grep_process.communicate() + #print(output) + f.write(output) + f = open("/home/bsmqris/twitmonitor/twit_failed.txt", "r") + result = { + "error_401":0, + "error_403":0, + "error_400":0, + "error_429":0, + "error_503":0, + } + for x in f: + error=x.split() + raw_error=error[14] + clean_error = raw_error[1:4] + if(int(clean_error) == 401): + result["error_401"]+=1 + elif(int(clean_error) == 403): + result["error_403"]+=1 + elif(int(clean_error) == 400): + result["error_400"]+=1 + elif(int(clean_error) == 429): + result["error_429"]+=1 + else: + result["error_503"]+=1 + return result + +with open(f"/home/bsmqris/twitmonitor/twit_monitor.txt", 'w') as f: + f.write(quote_tweet()) + f.write(reply_tweet()) + error = twit_failed2() + f.write(f"Error 401: {error['error_401']}\n") + f.write(f"Error 403: {error['error_403']}\n") + f.write(f"Error 400: {error['error_400']}\n") + f.write(f"Error 429: {error['error_429']}\n") + f.write(f"Error 503: {error['error_503']}\n") \ No newline at end of file diff --git a/monitor-freya.py b/monitor-freya.py new file mode 100644 index 0000000..66be363 --- /dev/null +++ b/monitor-freya.py @@ -0,0 +1,224 @@ +#!/usr/bin/env python3 +import subprocess +import datetime +import json +import sys + +now = datetime.datetime.now() +date = now.strftime('%Y%m%d') + +server_name = 'freya.cayangqu.com' + +try: + nama_log = f"auto_replytoaccNretweet.log.{sys.argv[2]}" +except: + nama_log = "auto_replytoaccNretweet.log" + +def twit_sent(): + ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "twit sent with text"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = wc_process.communicate() + return f"Twit sent: {output}" + +def twit_sent_2(): + ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log2/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "twit sent with text"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = wc_process.communicate() + return f"Twit sent: {output}" + +def twit_sent_3(): + ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log3/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "twit sent with text"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = wc_process.communicate() + return f"Twit sent: {output}" + +def twit_failed(): + ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "twit failed"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = wc_process.communicate() + return f"Twit failed: {output}" + +def twit_failed_2(): + ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log2/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "twit failed"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = wc_process.communicate() + return f"Twit failed: {output}" + +def twit_failed_3(): + ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log3/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "twit failed"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = wc_process.communicate() + return f"Twit failed: {output}" + +def quote_tweet(): + ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "quote twit sent"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = wc_process.communicate() + return f"Twit quoted: {output}" + +def quote_tweet2(): + ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log2/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "quote twit sent"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = wc_process.communicate() + return f"Twit quoted: {output}" + +def quote_tweet3(): + ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log3/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "quote twit sent"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = wc_process.communicate() + return f"Twit quoted: {output}" + +def reply_tweet(): + ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "reply twit sent"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = wc_process.communicate() + return f"Twit replied: {output}" + +def reply_tweet2(): + ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log2/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "reply twit sent"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = wc_process.communicate() + return f"Twit replied: {output}" + +def reply_tweet3(): + ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log3/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "reply twit sent"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = wc_process.communicate() + return f"Twit replied: {output}" + +def twit_failed2(): + with open(f"/home/telakses/twitmonitor/twit_failed.txt", 'w') as f: + ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "twit failed"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = grep_process.communicate() + #print(output) + f.write(output) + f = open("/home/telakses/twitmonitor/twit_failed.txt", "r") + result = { + "error_401":0, + "error_403":0, + "error_400":0, + "error_429":0, + "error_503":0, + } + for x in f: + error=x.split() + raw_error=error[14] + clean_error = raw_error[1:4] + if(int(clean_error) == 401): + result["error_401"]+=1 + elif(int(clean_error) == 403): + result["error_403"]+=1 + elif(int(clean_error) == 400): + result["error_400"]+=1 + elif(int(clean_error) == 429): + result["error_429"]+=1 + else: + result["error_503"]+=1 + return result + +def twit_failed2_2(): + with open(f"/home/telakses/twitmonitor/twit_failed_log2.txt", 'w') as f: + ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log2/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "twit failed"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = grep_process.communicate() + #print(output) + f.write(output) + f = open("/home/telakses/twitmonitor/twit_failed_log2.txt", "r") + result = { + "error_401":0, + "error_403":0, + "error_400":0, + "error_429":0, + "error_503":0, + } + for x in f: + error=x.split() + raw_error=error[14] + clean_error = raw_error[1:4] + if(int(clean_error) == 401): + result["error_401"]+=1 + elif(int(clean_error) == 403): + result["error_403"]+=1 + elif(int(clean_error) == 400): + result["error_400"]+=1 + elif(int(clean_error) == 429): + result["error_429"]+=1 + else: + result["error_503"]+=1 + return result + +def twit_failed2_3(): + with open(f"/home/telakses/twitmonitor/twit_failed_log3.txt", 'w') as f: + ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log3/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "twit failed"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = grep_process.communicate() + #print(output) + f.write(output) + f = open("/home/telakses/twitmonitor/twit_failed_log3.txt", "r") + result = { + "error_401":0, + "error_403":0, + "error_400":0, + "error_429":0, + "error_503":0, + } + for x in f: + error=x.split() + raw_error=error[14] + clean_error = raw_error[1:4] + if(int(clean_error) == 401): + result["error_401"]+=1 + elif(int(clean_error) == 403): + result["error_403"]+=1 + elif(int(clean_error) == 400): + result["error_400"]+=1 + elif(int(clean_error) == 429): + result["error_429"]+=1 + else: + result["error_503"]+=1 + return result + +with open(f"/home/telakses/twitmonitor/twit_monitor.txt", 'w') as f: + f.write("\n") + f.write("Freya Log1:\n") + f.write(quote_tweet()) + f.write(reply_tweet()) + error = twit_failed2() + f.write(f"Error 401: {error['error_401']}\n") + f.write(f"Error 403: {error['error_403']}\n") + f.write(f"Error 400: {error['error_400']}\n") + f.write(f"Error 429: {error['error_429']}\n") + f.write(f"Error 503: {error['error_503']}\n") + f.write("\n") + f.write("Freya Log2:\n") + f.write(quote_tweet2()) + f.write(reply_tweet2()) + error2 = twit_failed2_2() + f.write(f"Error 401: {error2['error_401']}\n") + f.write(f"Error 403: {error2['error_403']}\n") + f.write(f"Error 400: {error2['error_400']}\n") + f.write(f"Error 429: {error2['error_429']}\n") + f.write(f"Error 503: {error2['error_503']}\n") + f.write("\n") + f.write("Freya Log3:\n") + f.write(quote_tweet3()) + f.write(reply_tweet3()) + error3 = twit_failed2_3() + f.write(f"Error 401: {error3['error_401']}\n") + f.write(f"Error 403: {error3['error_403']}\n") + f.write(f"Error 400: {error3['error_400']}\n") + f.write(f"Error 429: {error3['error_429']}\n") + f.write(f"Error 503: {error3['error_503']}\n") \ No newline at end of file diff --git a/monitor-lala.py b/monitor-lala.py new file mode 100644 index 0000000..8fe17aa --- /dev/null +++ b/monitor-lala.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 +import subprocess +import datetime +import json +import sys + +now = datetime.datetime.now() +date = now.strftime('%Y%m%d') + +server_name = 'lala.cayangqu.com' + +try: + nama_log = f"auto_replytoaccNretweet.log.{sys.argv[2]}" +except: + nama_log = "auto_replytoaccNretweet.log" + +def twit_sent(): + ls_process = subprocess.Popen(["cat",f"/home/ditolak/buzz/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "twit sent with text"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = wc_process.communicate() + return f"Twit sent: {output}" + +def twit_failed(): + ls_process = subprocess.Popen(["cat",f"/home/ditolak/buzz/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "twit failed"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = wc_process.communicate() + return f"Twit failed: {output}" + +def quote_tweet(): + ls_process = subprocess.Popen(["cat",f"/home/ditolak/buzz/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "quote twit sent"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = wc_process.communicate() + return f"Twit quoted: {output}" + +def reply_tweet(): + ls_process = subprocess.Popen(["cat",f"/home/ditolak/buzz/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "reply twit sent"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = wc_process.communicate() + return f"Twit replied: {output}" + +def twit_failed2(): + with open(f"/home/ditolak/twitmonitor/twit_failed.txt", 'w') as f: + ls_process = subprocess.Popen(["cat",f"/home/ditolak/buzz/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "twit failed"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = grep_process.communicate() + #print(output) + f.write(output) + f = open("/home/ditolak/twitmonitor/twit_failed.txt", "r") + result = { + "error_401":0, + "error_403":0, + "error_400":0, + "error_429":0, + "error_503":0, + } + for x in f: + error=x.split() + raw_error=error[14] + clean_error = raw_error[1:4] + if(int(clean_error) == 401): + result["error_401"]+=1 + elif(int(clean_error) == 403): + result["error_403"]+=1 + elif(int(clean_error) == 400): + result["error_400"]+=1 + elif(int(clean_error) == 429): + result["error_429"]+=1 + else: + result["error_503"]+=1 + return result + +with open(f"/home/ditolak/twitmonitor/twit_monitor.txt", 'w') as f: + f.write(quote_tweet()) + f.write(reply_tweet()) + error = twit_failed2() + f.write(f"Error 401: {error['error_401']}\n") + f.write(f"Error 403: {error['error_403']}\n") + f.write(f"Error 400: {error['error_400']}\n") + f.write(f"Error 429: {error['error_429']}\n") + f.write(f"Error 503: {error['error_503']}\n") \ No newline at end of file diff --git a/monitor.py b/monitor.py index 1d57c1d..a3a252b 100644 --- a/monitor.py +++ b/monitor.py @@ -28,6 +28,20 @@ def twit_failed(): output, error = wc_process.communicate() return f"Twit failed: {output}" +def quote_tweet(): + ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "quote twit sent"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = wc_process.communicate() + return f"Twit quoted: {output}" + +def reply_tweet(): + ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True) + grep_process = subprocess.Popen(["grep", "reply twit sent"], stdin=ls_process.stdout, stdout=subprocess.PIPE, text=True) + wc_process = subprocess.Popen(["wc", "-l"], stdin=grep_process.stdout, stdout=subprocess.PIPE, text=True) + output, error = wc_process.communicate() + return f"Twit replied: {output}" + def twit_failed2(): with open(f"/home/telakses/twitmonitor/twit_failed.txt", 'w') as f: ls_process = subprocess.Popen(["cat",f"/home/telakses/buzz/{sys.argv[1]}/log/{nama_log}"], stdout=subprocess.PIPE, text=True) @@ -60,8 +74,8 @@ def twit_failed2(): return result with open(f"/home/telakses/twitmonitor/twit_monitor.txt", 'w') as f: - f.write(twit_sent()) - f.write(twit_failed()) + f.write(quote_tweet()) + f.write(reply_tweet()) error = twit_failed2() f.write(f"Error 401: {error['error_401']}\n") f.write(f"Error 403: {error['error_403']}\n") diff --git a/monitoring/ashel.txt b/monitoring/ashel.txt deleted file mode 100644 index 330df74..0000000 --- a/monitoring/ashel.txt +++ /dev/null @@ -1,7 +0,0 @@ -Twit sent: 195 -Twit failed: 0 -Error 401: 0 -Error 403: 0 -Error 400: 0 -Error 429: 0 -Error 503: 0 diff --git a/monitoring/calysta.txt b/monitoring/calysta.txt deleted file mode 100644 index 330df74..0000000 --- a/monitoring/calysta.txt +++ /dev/null @@ -1,7 +0,0 @@ -Twit sent: 195 -Twit failed: 0 -Error 401: 0 -Error 403: 0 -Error 400: 0 -Error 429: 0 -Error 503: 0 diff --git a/monitoring/collection.txt b/monitoring/collection.txt deleted file mode 100644 index 71377c2..0000000 --- a/monitoring/collection.txt +++ /dev/null @@ -1,7 +0,0 @@ -Twit sent: 193 -Twit failed: 2 -Error 401: 0 -Error 403: 2 -Error 400: 0 -Error 429: 0 -Error 503: 0 diff --git a/monitoring/devi.py b/monitoring/devi.py new file mode 100755 index 0000000..5db3d05 --- /dev/null +++ b/monitoring/devi.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 +import datetime +import os +import glob + +now = datetime.datetime.now() +date = now.strftime('%Y%m%d') + +cwd = os.getcwd() + +with open(f"{cwd}/monitoring/lala.txt") as f: + print("Lala") + print(f.read()) + +with open(f"{cwd}/monitoring/anin.txt") as f: + print("Anin") + print(f.read()) \ No newline at end of file diff --git a/monitoring/devi.txt b/monitoring/devi.txt deleted file mode 100644 index 9265fd6..0000000 --- a/monitoring/devi.txt +++ /dev/null @@ -1,7 +0,0 @@ -Twit sent: 185 -Twit failed: 0 -Error 401: 0 -Error 403: 0 -Error 400: 0 -Error 429: 0 -Error 503: 0 diff --git a/monitoring/eve.txt b/monitoring/eve.txt deleted file mode 100644 index 330df74..0000000 --- a/monitoring/eve.txt +++ /dev/null @@ -1,7 +0,0 @@ -Twit sent: 195 -Twit failed: 0 -Error 401: 0 -Error 403: 0 -Error 400: 0 -Error 429: 0 -Error 503: 0 diff --git a/monitoring/freya.txt b/monitoring/freya.txt deleted file mode 100644 index fd565eb..0000000 --- a/monitoring/freya.txt +++ /dev/null @@ -1,7 +0,0 @@ -Twit sent: 195 -Twit failed: 2 -Error 401: 0 -Error 403: 2 -Error 400: 0 -Error 429: 0 -Error 503: 0 diff --git a/monitoring/haerin.txt b/monitoring/haerin.txt deleted file mode 100644 index 330df74..0000000 --- a/monitoring/haerin.txt +++ /dev/null @@ -1,7 +0,0 @@ -Twit sent: 195 -Twit failed: 0 -Error 401: 0 -Error 403: 0 -Error 400: 0 -Error 429: 0 -Error 503: 0 diff --git a/monitoring/hanni.txt b/monitoring/hanni.txt deleted file mode 100644 index 7bb3675..0000000 --- a/monitoring/hanni.txt +++ /dev/null @@ -1,7 +0,0 @@ -Twit sent: 192 -Twit failed: 0 -Error 401: 0 -Error 403: 0 -Error 400: 0 -Error 429: 0 -Error 503: 0 diff --git a/monitoring/hyein.txt b/monitoring/hyein.txt deleted file mode 100644 index 0a2bd17..0000000 --- a/monitoring/hyein.txt +++ /dev/null @@ -1,7 +0,0 @@ -Twit sent: 193 -Twit failed: 0 -Error 401: 0 -Error 403: 0 -Error 400: 0 -Error 429: 0 -Error 503: 0 diff --git a/monitoring/lina.txt b/monitoring/lina.txt deleted file mode 100644 index c7b3078..0000000 --- a/monitoring/lina.txt +++ /dev/null @@ -1,7 +0,0 @@ -Twit sent: 182 -Twit failed: 2 -Error 401: 0 -Error 403: 2 -Error 400: 0 -Error 429: 0 -Error 503: 0 diff --git a/monitoring/noella.txt b/monitoring/noella.txt deleted file mode 100644 index 9265fd6..0000000 --- a/monitoring/noella.txt +++ /dev/null @@ -1,7 +0,0 @@ -Twit sent: 185 -Twit failed: 0 -Error 401: 0 -Error 403: 0 -Error 400: 0 -Error 429: 0 -Error 503: 0 diff --git a/monitoring/testc.py b/monitoring/testc.py new file mode 100644 index 0000000..4cb6ad0 --- /dev/null +++ b/monitoring/testc.py @@ -0,0 +1,22 @@ +import glob + +def readfile(): + read_path = glob.glob(f"*.txt") + return read_path + +nama_log = f"{readfile()}" + +#print(nama_log) + +with open(nama_log, 'r') as f: + lines = f.read().splitlines() + +for line in lines: + x1 = line.split(": ") + twit_sent = x1[1] + sum += int(twit_sent) + print(f"{twit_sent}") + + + +#print(list) \ No newline at end of file diff --git a/monitoring/util.py b/monitoring/util.py index 9517e5d..318fec6 100755 --- a/monitoring/util.py +++ b/monitoring/util.py @@ -1,12 +1,34 @@ #!/usr/bin/env python3 import datetime import os +import glob now = datetime.datetime.now() date = now.strftime('%Y%m%d') cwd = os.getcwd() +#def readfile(): +# read_path = glob.glob(f"*.txt") +# return read_path + +#print(readfile()) + +#def split_txt(readfile): +# with open(readfile, 'r') as f: +# txt = f.read() +# ret = [x.split(': ')[1] for x in txt.split('\n')] +# +# return ret + +#print(split_txt(readfile)) + +#def calc(total, current): +# with open(txt.split, 'r') as f: +# num = float(line) +# total += num +# f.write(line) + with open(f"{cwd}/monitoring/haerin.txt") as f: print("Haerin") print(f.read()) @@ -19,9 +41,9 @@ with open(f"{cwd}/monitoring/hanni.txt") as f: print("Hanni") print(f.read()) -with open(f"{cwd}/monitoring/noella.txt") as f: - print("Noella") - print(f.read()) +#with open(f"{cwd}/monitoring/noella.txt") as f: +# print("Noella") +# print(f.read()) with open(f"{cwd}/monitoring/lina.txt") as f: print("Lina") @@ -43,9 +65,9 @@ with open(f"{cwd}/monitoring/freya.txt") as f: print("Freya") print(f.read()) -with open(f"{cwd}/monitoring/calysta.txt") as f: - print("Calysta") - print(f.read()) +#with open(f"{cwd}/monitoring/calysta.txt") as f: +# print("Calysta") +# print(f.read()) with open(f"{cwd}/monitoring/eve.txt") as f: print("Eve") @@ -57,4 +79,66 @@ with open(f"{cwd}/monitoring/ashel.txt") as f: with open(f"{cwd}/monitoring/yuvia.txt") as f: print("Yuvia") - print(f.read()) \ No newline at end of file + print(f.read()) + +with open(f"{cwd}/monitoring/pocmandiri.txt") as f: + print("pocmandiri.tel-access") + print(f.read()) + +with open(f"{cwd}/monitoring/cindy.txt") as f: + print("Cindy") + print(f.read()) + +with open(f"{cwd}/monitoring/walletdemo.txt") as f: + print("wallet-demo.tel-access.com") + print(f.read()) + +with open(f"{cwd}/monitoring/ai.txt") as f: + print("Ai") + print(f.read()) + +with open(f"{cwd}/monitoring/anin.txt") as f: + print("Anin") + print(f.read()) + +with open(f"{cwd}/monitoring/lala.txt") as f: + print("Lala") + print(f.read()) + +with open(f"{cwd}/monitoring/demochat.txt") as f: + print("demochat-crm.tel-access.com") + print(f.read()) + +#with open(f"{cwd}/monitoring/jessica.txt") as f: +# print("Jessica") +# print(f.read()) + +#with open(f"{cwd}/monitoring/zahra.txt") as f: +# print("Zahra Yuriva") +# print(f.read()) + +#with open(f"{cwd}/monitoring/violeta.txt") as f: +# print("Violeta") +# print(f.read()) + +#with open(f"{cwd}/monitoring/smartrecord.txt") as f: +# print("smartrecord.tel-access.com") +# print(f.read()) + +#with open(f"{cwd}/monitoring/yuriva.txt") as f: +# print("Yuriva") +# print(f.read()) + +#print("Rekap:\n") +#for inp in glob.glob("{cwd}/monitoring/*.txt") +# +#with open('input.txt', 'r') as inp, open('output.txt', 'w') as outp: +# for line in inp: +# try: +# num = float(line) +# total += num +# outp.write(line) +# except ValueError: +# print('{} is not a number!'.format(line)) +# +#print('Total of all numbers: {}'.format(total)) \ No newline at end of file diff --git a/monitoring/wista.txt b/monitoring/wista.txt deleted file mode 100644 index 11d56a3..0000000 --- a/monitoring/wista.txt +++ /dev/null @@ -1,7 +0,0 @@ -Twit sent: 196 -Twit failed: 0 -Error 401: 0 -Error 403: 0 -Error 400: 0 -Error 429: 0 -Error 503: 0 diff --git a/monitoring/yuvia.txt b/monitoring/yuvia.txt deleted file mode 100644 index 11d56a3..0000000 --- a/monitoring/yuvia.txt +++ /dev/null @@ -1,7 +0,0 @@ -Twit sent: 196 -Twit failed: 0 -Error 401: 0 -Error 403: 0 -Error 400: 0 -Error 429: 0 -Error 503: 0 diff --git a/start.sh b/start.sh index 61313e5..aa0d50e 100755 --- a/start.sh +++ b/start.sh @@ -36,15 +36,15 @@ send "Rahasia123!\r" interact #Noella -spawn ssh -p4848 telakses@noella.cayangqu.com './twitmonitor/monitor.py' $path $date -expect "password:" -send "Rahasia123!\r" -interact -sleep 1 -spawn scp -P4848 telakses@noella.cayangqu.com:/home/telakses/twitmonitor/twit_monitor.txt ./monitoring/noella.txt -expect "password:" -send "Rahasia123!\r" -interact +#spawn ssh -p4848 telakses@noella.cayangqu.com './twitmonitor/monitor.py' $path $date +#expect "password:" +#send "Rahasia123!\r" +#interact +#sleep 1 +#spawn scp -P4848 telakses@noella.cayangqu.com:/home/telakses/twitmonitor/twit_monitor.txt ./monitoring/noella.txt +#expect "password:" +#send "Rahasia123!\r" +#interact #Lina spawn ssh -p4848 telakses@lina.cayangqu.com './twitmonitor/monitor.py' $path $date @@ -80,7 +80,7 @@ send "2020 ga tau kemana\r" interact #Devi -spawn ssh -p4848 bsmqris@devi.cayangqu.com './twitmonitor/monitor.py' $path $date +spawn ssh -p4848 bsmqris@devi.cayangqu.com python3.8 './twitmonitor/monitor.py' $path $date expect "password:" send "2020 kena pa lo\r" interact @@ -102,15 +102,15 @@ send "2020 Rahasia123!\r" interact #Calysta -spawn ssh -p4848 telakses@calysta.cayangqu.com './twitmonitor/monitor.py' $path $date -expect "password:" -send "Rahasia123!\r" -interact -sleep 1 -spawn scp -P4848 telakses@calysta.cayangqu.com:/home/telakses/twitmonitor/twit_monitor.txt ./monitoring/calysta.txt -expect "password:" -send "Rahasia123!\r" -interact +#spawn ssh -p4848 telakses@calysta.cayangqu.com './twitmonitor/monitor.py' $path $date +#expect "password:" +#send "Rahasia123!\r" +#interact +#sleep 1 +#spawn scp -P4848 telakses@calysta.cayangqu.com:/home/telakses/twitmonitor/twit_monitor.txt ./monitoring/calysta.txt +#expect "password:" +#send "Rahasia123!\r" +#interact #Eve spawn ssh -p4848 telakses@eve.cayangqu.com './twitmonitor/monitor.py' $path $date @@ -135,7 +135,7 @@ send "Rahasia123!\r" interact #Yuvia -spawn ssh -p4848 vconf@yuvia.cayangqu.com './twitmonitor/monitor.py' $path $date +spawn ssh -p4848 vconf@yuvia.cayangqu.com python3.8 './twitmonitor/monitor.py' $path $date expect "password:" send "2020 salah lagi\r" interact @@ -145,5 +145,137 @@ expect "password:" send "2020 salah lagi\r" interact +#POC Mandiri +spawn ssh -p4848 telakses@pocmandiri.tel-access.com './twitmonitor/monitor.py' $path $date +expect "password:" +send "Rahasia123!\r" +interact +sleep 1 +spawn scp -P4848 telakses@pocmandiri.tel-access.com:/home/telakses/twitmonitor/twit_monitor.txt ./monitoring/pocmandiri.txt +expect "password:" +send "Rahasia123!\r" +interact + +#Cindy +spawn ssh -p4848 telakses@cindy.cayangqu.com './twitmonitor/monitor.py' $path $date +expect "password:" +send "Rahasia123!\r" +interact +sleep 1 +spawn scp -P4848 telakses@cindy.cayangqu.com:/home/telakses/twitmonitor/twit_monitor.txt ./monitoring/cindy.txt +expect "password:" +send "Rahasia123!\r" +interact + +#Wallet-demo +spawn ssh -p4848 telakses@wallet-demo.tel-access.com './twitmonitor/monitor.py' $path $date +expect "password:" +send "Rahasia123!\r" +interact +sleep 1 +spawn scp -P4848 telakses@wallet-demo.tel-access.com:/home/telakses/twitmonitor/twit_monitor.txt ./monitoring/walletdemo.txt +expect "password:" +send "Rahasia123!\r" +interact + +#AI +spawn ssh -p4848 telakses@ai.cayangqu.com './twitmonitor/monitor.py' $path $date +expect "password:" +send "Rahasia123!\r" +interact +sleep 1 +spawn scp -P4848 telakses@ai.cayangqu.com:/home/telakses/twitmonitor/twit_monitor.txt ./monitoring/ai.txt +expect "password:" +send "Rahasia123!\r" +interact + +#Anin +spawn ssh -p4848 biasa@anin.cayangqu.com python3.8 './twitmonitor/monitor.py' $path $date +expect "password:" +send "2020 seperti kemarin\r" +interact +sleep 1 +spawn scp -P4848 biasa@anin.cayangqu.com:/home/biasa/twitmonitor/twit_monitor.txt ./monitoring/anin.txt +expect "password:" +send "2020 seperti kemarin\r" +interact + +#Lala +spawn ssh -p4848 ditolak@lala.cayangqu.com python3.8 './twitmonitor/monitor.py' $path $date +expect "password:" +send "2020 Rahasia123!\r" +interact +sleep 1 +spawn scp -P4848 ditolak@lala.cayangqu.com:/home/ditolak/twitmonitor/twit_monitor.txt ./monitoring/lala.txt +expect "password:" +send "2020 Rahasia123!\r" +interact + +#Demochat +spawn ssh -p4848 telakses@demochat-crm.tel-access.com './twitmonitor/monitor.py' $path $date +expect "password:" +send "rahasia\r" +interact +sleep 1 +spawn scp -P4848 telakses@demochat-crm.tel-access.com:/home/telakses/twitmonitor/twit_monitor.txt ./monitoring/demochat.txt +expect "password:" +send "rahasia\r" +interact + +#Jessica +#spawn ssh -p4848 bebas@jessica.chandrawisesa.com './twitmonitor/monitor.py' $path $date +#expect "password:" +#send "kosongin aja\r" +#interact +#sleep 1 +#spawn scp -P4848 bebas@jessica.chandrawisesa.com:/home/bebas/twitmonitor/twit_monitor.txt ./monitoring/jessica.txt +#expect "password:" +#send "kosongin aja\r" +#interact + +#Zahra +#spawn ssh -p4848 telakses@zahra.yuriva.com './twitmonitor/monitor.py' $path $date +#expect "password:" +#send "2020 Rahasia123!\r" +#interact +#sleep 1 +#spawn scp -P4848 telakses@zahra.yuriva.com:/home/telakses/twitmonitor/twit_monitor.txt ./monitoring/zahra.txt +#expect "password:" +#send "2020 Rahasia123!\r" +#interact + +#Violeta +#spawn ssh -p4848 coba@violeta.cayangqu.com './twitmonitor/monitor.py' $path $date +#expect "password:" +#send "tadi udah kan\r" +#interact +#sleep 1 +#spawn scp -P4848 coba@violeta.cayangqu.com:/home/coba/twitmonitor/twit_monitor.txt ./monitoring/violeta.txt +#expect "password:" +#send "tadi udah kan\r" +#interact + +#Smart Record +#spawn ssh -p4848 telakses@smartrecord.tel-access.com './twitmonitor/monitor.py' $path $date +#expect "password:" +#send "Rahasia123!\r" +#interact +#sleep 1 +#spawn scp -P4848 telakses@smartrecord.tel-access.com:/home/telakses/twitmonitor/twit_monitor.txt ./monitoring/smartrecord.txt +#expect "password:" +#send "Rahasia123!\r" +#interact + +#Yuriva +#spawn ssh -p4848 bebas@yuriva.com './twitmonitor/monitor.py' $path $date +#expect "password:" +#send "kosongin aja\r" +#interact +#sleep 1 +#spawn scp -P4848 bebas@yuriva.com:/home/bebas/twitmonitor/twit_monitor.txt ./monitoring/yuriva.txt +#expect "password:" +#send "kosongin aja\r" +#interact + spawn ./monitoring/util.py interact \ No newline at end of file