-
Notifications
You must be signed in to change notification settings - Fork 3
/
zabbix_info.sh
executable file
·1428 lines (1255 loc) · 34.4 KB
/
zabbix_info.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
# ------------------------------#
# Oracle - Zabbix Info (CRMALL) #
# #
# Josue Pirolo 03/2015 #
# 02/2016 # Update #
# ------------------------------#
##
## Menu
## Execute the Following:
## 1 - zabbix_info.sh oracle_env
## If the Oracle Variables are already set, then execute the following:
## 2 - zabbix_info.sh verify_user_zabbix
##
# Tools
DATA=$(date +%Y-%m-%d)
DATA_HORA=$(date +%Y-%m-%d-%H_%M_%S)
CAT=$(which cat)
GREP=$(which grep)
SED=$(which sed)
CUT=$(which cut)
DATE=$(which date)
HEAD=$(which head)
WC=$(which wc)
RM=$(which rm)
FIND=$(which find)
# Config Files Path
CONFIG_FILE="/var/lib/zabbix/scripts/config_user"
ORACLE_FILE="/var/lib/zabbix/scripts/config_oracle"
##
##
## Oracle Variables Isolated Fuction
##
function oracle_env () {
DIR1="/u01" # Oracle XE - Versao 11g
DIR2="/usr/lib/oracle" # Oracle XE - Versao 10g
##
if [ -d ${DIR1} ]; then
#
FIND1=$(find ${DIR1} -name oracle_env.sh)
#
${CAT} ${FIND1} > ${ORACLE_FILE}
#
. $ORACLE_FILE
elif [ -d ${DIR2} ]; then
#
FIND2=$(find ${DIR2} -name oracle_env.sh)
#
${CAT} ${FIND2} > ${ORACLE_FILE}
#
. $ORACLE_FILE
else
echo "Oracle Database not installed ou it is a Oracle SE1,SE or EE."
fi
}
##
## End of Isolated Function
##
## Load Oracle Paths
if [ -f ${ORACLE_FILE} ]; then
. ${ORACLE_FILE}
else
oracle_env
fi
##
OS_VERSION=$(sed -e 's/\<[a-zA-Z]*\>//g' /etc/redhat-release | sed -e 's/()//g' | tr -d " \n")
CENTOS_5="5.0"
CENTOS_6="6.0"
if [ $(echo "${OS_VERSION} < ${CENTOS_6}"|bc) -eq 1 ]; then
SQLPLUS=$(${FIND} $ORACLE_HOME/bin -name sqlplus)
elif [ $(echo "${OS_VERSION} > ${CENTOS_6}"|bc) -eq 1 ]; then
SQLPLUS=$(which sqlplus)
fi
##
#
## Functions
##
function password () {
echo "Informe o usuario SYSADMIN"
read SYSTEM
echo "Informe a senha do Usuario SYSTEM"
read -s SYSTEM_PASS
}
function verify_user_zabbix () {
#
password
#
# Continuando com os passos seguintes
#
RETORNO=$($SQLPLUS -S ${SYSTEM}/${SYSTEM_PASS} as sysdba <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
set numformat 99999999999999999999
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT COUNT(USERNAME) FROM DBA_USERS WHERE USERNAME ='ZABBIX';
EOF
)
#echo $RETORNO
##
##
if [ ${RETORNO} -eq 1 ]; then
echo "Usuario existente"
exit 0
else
echo "Usuario nao existe...Inicializando processo de criacao"
gen_pass_for_zabbix
fi
}
function gen_pass_for_zabbix () {
echo "Criando usuario zabbix"
GEN_PASS=$(${DATE} +%s | sha256sum | base64 | ${HEAD} -c 12 ; echo)
echo "USERNAME=\"zabbix"\" > ${CONFIG_FILE}
echo "PASSWORD=\"${GEN_PASS}"\" >> ${CONFIG_FILE}
PASSWORD_ZABBIX=$(${CAT} ${CONFIG_FILE} | ${GREP} PASS | ${CUT} -d'"' -f2)
echo "CREATE PROFILE CRMALL_3 LIMIT
COMPOSITE_LIMIT UNLIMITED
SESSIONS_PER_USER UNLIMITED
CPU_PER_SESSION UNLIMITED
CPU_PER_CALL UNLIMITED
LOGICAL_READS_PER_SESSION UNLIMITED
LOGICAL_READS_PER_CALL UNLIMITED
IDLE_TIME UNLIMITED
CONNECT_TIME UNLIMITED
PRIVATE_SGA UNLIMITED
FAILED_LOGIN_ATTEMPTS 10
PASSWORD_LIFE_TIME UNLIMITED
PASSWORD_REUSE_TIME UNLIMITED
PASSWORD_REUSE_MAX UNLIMITED
PASSWORD_VERIFY_FUNCTION NULL
PASSWORD_LOCK_TIME 1
PASSWORD_GRACE_TIME 7
/
CREATE USER ZABBIX
IDENTIFIED BY \"${PASSWORD_ZABBIX}\"
DEFAULT TABLESPACE USERS
TEMPORARY TABLESPACE TEMP
PROFILE DEFAULT
ACCOUNT UNLOCK
/
GRANT ALTER SESSION TO ZABBIX
/
GRANT CREATE SESSION TO ZABBIX
/
GRANT CONNECT TO ZABBIX
/
ALTER USER ZABBIX DEFAULT ROLE ALL
/
GRANT ALTER USER TO ZABBIX
/
GRANT CREATE PROCEDURE TO ZABBIX
/
GRANT SELECT ON V_\$INSTANCE TO ZABBIX
/
GRANT SELECT ON DBA_USERS TO ZABBIX
/
GRANT SELECT ON V_\$LOG_HISTORY TO ZABBIX
/
GRANT SELECT ON V_\$PARAMETER TO ZABBIX
/
GRANT SELECT ON SYS.DBA_AUDIT_SESSION TO ZABBIX
/
GRANT SELECT ON V_\$LOCK TO ZABBIX
/
GRANT SELECT ON DBA_REGISTRY TO ZABBIX
/
GRANT SELECT ON V_\$LIBRARYCACHE TO ZABBIX
/
GRANT SELECT ON V_\$SYSSTAT TO ZABBIX
/
GRANT SELECT ON V_\$PARAMETER TO ZABBIX
/
GRANT SELECT ON V_\$LATCH TO ZABBIX
/
GRANT SELECT ON V_\$PGASTAT TO ZABBIX
/
GRANT SELECT ON V_\$SGASTAT TO ZABBIX
/
GRANT SELECT ON V_\$LIBRARYCACHE TO ZABBIX
/
GRANT SELECT ON V_\$PROCESS TO ZABBIX
/
GRANT SELECT ON DBA_DATA_FILES TO ZABBIX
/
GRANT SELECT ON DBA_TEMP_FILES TO ZABBIX
/
GRANT SELECT ON DBA_FREE_SPACE TO ZABBIX
/
GRANT SELECT ON V_\$SYSTEM_EVENT TO ZABBIX
/
GRANT EXECUTE ON DBMS_NETWORK_ACL_ADMIN TO ZABBIX
/
GRANT SELECT ON SYS.V_\$SESSION TO ZABBIX
/
GRANT SELECT ON SYS.V_\$SHARED_SERVER TO ZABBIX
/
GRANT SELECT ON SYS.V_\$SESSION TO ZABBIX
/
GRANT SELECT ON SYS.DBA_OBJECTS TO ZABBIX
/
GRANT SELECT ON SYS.DBA_DATA_FILES TO ZABBIX
/
GRANT SELECT ON SYS.DBA_SEGMENTS TO ZABBIX
/
GRANT SELECT ON SYS.DBA_TABLESPACES TO ZABBIX
/
GRANT SELECT ON SYS.V_\$DATABASE TO ZABBIX
/
GRANT SELECT ON SYS.V_\$ARCHIVED_LOG TO ZABBIX
/
GRANT SELECT ON SYS.V_\$PARAMETER TO ZABBIX
/
GRANT SELECT ON SYS.V_\$PGASTAT TO ZABBIX
/
GRANT SELECT ON SYS.V_\$SGASTAT TO ZABBIX
/
GRANT SELECT ON SYS.V_\$SYSTEM_EVENT TO ZABBIX
/
GRANT SELECT ON SYS.DBA_USERS TO ZABBIX
/
GRANT SELECT ON SYS.V_\$LOG_HISTORY TO ZABBIX
/
GRANT SELECT ON SYS.V_\$DATABASE TO ZABBIX
/
GRANT SELECT ON SYS.DBA_INDEXES TO ZABBIX
/
GRANT SELECT ON V_\$ROWCACHE TO ZABBIX
/
GRANT SELECT ON V_\$PARAMETER TO ZABBIX
/
GRANT SELECT ON V_\$STATNAME TO ZABBIX
/
GRANT SELECT ON V_\$SESSTAT TO ZABBIX
/
GRANT SELECT ON DBA_ROLE_PRIVS TO ZABBIX
/
GRANT SELECT ON DBA_ROLES TO ZABBIX
/
ALTER USER SYSTEM PROFILE CRMALL_3
/
-- ALTER USER CRMALL PROFILE CRMALL_3
-- /
-- ALTER USER CLIENTE PROFILE CRMALL_3
-- /
ALTER USER CORREIO PROFILE CRMALL_3
/
CREATE OR REPLACE FUNCTION ZABBIX.FUNC_USERNAME_LIST(PA_OPTION VARCHAR2) RETURN VARCHAR2 IS
V_CRMALL_USER DBA_USERS.USERNAME%TYPE;
V_CLIENTE_USER DBA_USERS.USERNAME%TYPE;
BEGIN
SELECT USERNAME INTO V_CRMALL_USER FROM DBA_USERS WHERE USERNAME LIKE '%CRMALL%';
--
SELECT USERNAME INTO V_CLIENTE_USER FROM DBA_USERS WHERE USERNAME LIKE '%CLIENTE%';
IF PA_OPTION = 'CRMALL' THEN
RETURN V_CRMALL_USER;
ELSIF PA_OPTION = 'CLIENTE' THEN
RETURN V_CLIENTE_USER;
END IF;
END;
/
CREATE OR REPLACE PROCEDURE ZABBIX.PROC_USERNAME_PROFILE IS
BEGIN
EXECUTE IMMEDIATE ('ALTER USER '||(FUNC_USERNAME_LIST('CRMALL'))||' PROFILE CRMALL_3');
--
EXECUTE IMMEDIATE ('ALTER USER '||(FUNC_USERNAME_LIST('CLIENTE'))||' PROFILE CRMALL_3');
END;
/
EXECUTE ZABBIX.PROC_USERNAME_PROFILE()
/
QUIT
/" > /var/lib/zabbix/scripts/oracle-zabbix/Criar_usuario_zabbix.sql
##
##
echo " "
$SQLPLUS -S ${SYSTEM}/${SYSTEM_PASS} as sysdba @Criar_usuario_zabbix.sql
$RM -f Criar_usuario_zabbix.sql
echo "Completed Sucessfully"
##
##
}
## Load Zabbix User Variables #
if [ -f $CONFIG_FILE ]; then
. $CONFIG_FILE #
# echo "Usuario Zabbix Existente, pronto para utilizar"
else
echo "Creating Zabbix User Config File..."
verify_user_zabbix
fi
## #
#
##
function total_tbs_crmall() {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
set numformat 99999999999999999999
SELECT SUM(DT.BYTES)
FROM DBA_DATA_FILES DT
INNER JOIN DBA_USERS U
ON U.DEFAULT_TABLESPACE = DT.TABLESPACE_NAME
AND DT.TABLESPACE_NAME LIKE '%CRMALL%'
AND U.PROFILE NOT IN ('DEFAULT','MONITORING_PROFILE','CRMALL_4C_CLIENTES_USER','HOMOLOGACAO','CRMALL_4C_INTERNO_USER');
EOF
}
function total_tbs_cliente() {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
set numformat 99999999999999999999
SELECT SUM(DT.BYTES)
FROM DBA_DATA_FILES DT
INNER JOIN DBA_USERS U
ON U.DEFAULT_TABLESPACE = DT.TABLESPACE_NAME
AND DT.TABLESPACE_NAME LIKE '%CLIENTE%'
AND U.PROFILE NOT IN ('DEFAULT','MONITORING_PROFILE','CRMALL_4C_CLIENTES_USER','HOMOLOGACAO','CRMALL_4C_INTERNO_USER');
EOF
}
function total_tbs_correio() {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
set numformat 99999999999999999999
SELECT SUM(DT.BYTES)
FROM DBA_DATA_FILES DT
INNER JOIN DBA_USERS U
ON U.DEFAULT_TABLESPACE = DT.TABLESPACE_NAME
AND DT.TABLESPACE_NAME LIKE '%CORREIO%'
AND U.PROFILE NOT IN ('DEFAULT','MONITORING_PROFILE','CRMALL_4C_CLIENTES_USER','HOMOLOGACAO','CRMALL_4C_INTERNO_USER');
EOF
}
function total_tbs_system() {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
set numformat 99999999999999999999
SELECT SUM(DT.BYTES)
FROM DBA_DATA_FILES DT
INNER JOIN DBA_USERS U
ON U.DEFAULT_TABLESPACE = DT.TABLESPACE_NAME
AND DT.TABLESPACE_NAME LIKE '%SYSTEM%'
AND U.PROFILE NOT IN ('DEFAULT','MONITORING_PROFILE','CRMALL_4C_CLIENTES_USER','HOMOLOGACAO','CRMALL_4C_INTERNO_USER');
EOF
}
function lista_tablespace() {
cd /var/lib/zabbix/scripts/
$SQLPLUS -S $USERNAME/$PASSWORD>tablespaces 2>&1 <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT DT.TABLESPACE_NAME FROM DBA_TABLESPACES DT INNER JOIN
DBA_USERS U ON DT.TABLESPACE_NAME = U.DEFAULT_TABLESPACE AND U.PROFILE NOT IN ('MONITORING_PROFILE','DEFAULT','CRMALL_4C_CLIENTES_USER','HOMOLOGACAO')
AND DT.TABLESPACE_NAME <> 'USERS'
ORDER BY USERNAME
/
--SELECT DEFAULT_TABLESPACE FROM DBA_USERS WHERE PROFILE = 'CRMALL_4C_CLIENTES';
EOF
TOTAL=`cat tablespaces | wc -l`
i=0
# Cria lista JSON
echo "{" > lista_tablespaces
echo " \"data\":[" >> lista_tablespaces
for X in `cat tablespaces`; do
i=$((i+1))
if [ $TOTAL -eq $i ]; then
echo " { \"{#TABLESPACE}\":\"${X}\"}" >> lista_tablespaces
else
echo " { \"{#TABLESPACE}\":\"${X}\"}," >> lista_tablespaces
fi
done
echo " ]" >> lista_tablespaces
echo "}" >> lista_tablespaces
rm tablespaces
exit 0;
}
function lista_users() {
cd /var/lib/zabbix/scripts/
$SQLPLUS -S $USERNAME/$PASSWORD>users 2>&1 <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT U.USERNAME FROM DBA_USERS U WHERE U.PROFILE NOT IN ('MONITORING_PROFILE','DEFAULT','HOMOLOGACAO','SYSTEM')
ORDER BY U.USERNAME
/
EOF
TOTALUSER=`cat users | wc -l`
ii=0
# Cria lista JSON
echo "{" > lista_users
echo " \"data\":[" >> lista_users
for X in `cat users`; do
ii=$((ii+1))
if [ $TOTALUSER -eq $ii ]; then
echo " { \"{#USER}\":\"${X}\"}" >> lista_users
else
echo " { \"{#USER}\":\"${X}\"}," >> lista_users
fi
done
echo " ]" >> lista_users
echo "}" >> lista_users
rm users
exit 0;
}
function used_tbs_crmall() {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
set numformat 99999999999999999999
SELECT
SUM(BYTES)
FROM
DBA_SEGMENTS
WHERE
TABLESPACE_NAME = (SELECT DEFAULT_TABLESPACE FROM DBA_USERS WHERE USERNAME LIKE '%CRMALL%' AND PROFILE NOT IN ('DEFAULT','MONITORING_PROFILE'))
GROUP BY
TABLESPACE_NAME;
EOF
}
function used_tbs_cliente() {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
set numformat 99999999999999999999
SELECT
SUM(BYTES)
FROM
DBA_SEGMENTS
WHERE
TABLESPACE_NAME = (SELECT DEFAULT_TABLESPACE FROM DBA_USERS WHERE USERNAME LIKE '%CLIENTE%' AND PROFILE NOT IN ('DEFAULT','MONITORING_PROFILE'))
GROUP BY
TABLESPACE_NAME;
EOF
}
function used_tbs_correio() {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
set numformat 99999999999999999999
SELECT
SUM(BYTES)
FROM
DBA_SEGMENTS
WHERE
TABLESPACE_NAME = (SELECT DEFAULT_TABLESPACE FROM DBA_USERS WHERE USERNAME LIKE '%CORREIO%' AND PROFILE NOT IN ('DEFAULT','MONITORING_PROFILE'))
GROUP BY
TABLESPACE_NAME;
EOF
}
function used_tbs_system() {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
set numformat 99999999999999999999
SELECT
SUM(BYTES)
FROM
DBA_SEGMENTS
WHERE
TABLESPACE_NAME = (SELECT DEFAULT_TABLESPACE FROM DBA_USERS WHERE USERNAME LIKE '%SYSTEM%' AND PROFILE NOT IN ('DEFAULT','MONITORING_PROFILE'))
GROUP BY
TABLESPACE_NAME;
EOF
}
function account_status_crmall() {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT
CASE
WHEN ACCOUNT_STATUS = 'OPEN'
THEN '0'
WHEN ACCOUNT_STATUS = 'LOCKED'
THEN '1'
WHEN ACCOUNT_STATUS = 'EXPIRED'
THEN '2'
WHEN ACCOUNT_STATUS = 'EXPIRED(GRACE)'
THEN '3'
WHEN ACCOUNT_STATUS = 'LOCKED(TIME)'
THEN '4'
END AS ACCOUNT_STATUS
FROM DBA_USERS
WHERE USERNAME = (SELECT USERNAME FROM DBA_USERS WHERE USERNAME LIKE '%CRMALL%' AND PROFILE NOT IN ('DEFAULT','MONITORING_PROFILE'))
/
EOF
}
function account_status_cliente() {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT
CASE
WHEN ACCOUNT_STATUS = 'OPEN'
THEN '0'
WHEN ACCOUNT_STATUS = 'LOCKED'
THEN '1'
WHEN ACCOUNT_STATUS = 'EXPIRED'
THEN '2'
WHEN ACCOUNT_STATUS = 'EXPIRED(GRACE)'
THEN '3'
WHEN ACCOUNT_STATUS = 'LOCKED(TIME)'
THEN '4'
END AS ACCOUNT_STATUS
FROM DBA_USERS
WHERE USERNAME = (SELECT USERNAME FROM DBA_USERS WHERE USERNAME LIKE '%CLIENTE%' AND PROFILE NOT IN ('DEFAULT','MONITORING_PROFILE'))
/
EOF
}
function account_status_correio() {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT
CASE
WHEN ACCOUNT_STATUS = 'OPEN'
THEN '0'
WHEN ACCOUNT_STATUS = 'LOCKED'
THEN '1'
WHEN ACCOUNT_STATUS = 'EXPIRED'
THEN '2'
WHEN ACCOUNT_STATUS = 'EXPIRED(GRACE)'
THEN '3'
WHEN ACCOUNT_STATUS = 'LOCKED(TIME)'
THEN '4'
END AS ACCOUNT_STATUS
FROM DBA_USERS
WHERE USERNAME = (SELECT USERNAME FROM DBA_USERS WHERE USERNAME LIKE '%CORREIO%' AND PROFILE NOT IN ('DEFAULT','MONITORING_PROFILE'))
/
EOF
}
function account_status_system() {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT
CASE
WHEN ACCOUNT_STATUS = 'OPEN'
THEN '0'
WHEN ACCOUNT_STATUS = 'LOCKED'
THEN '1'
WHEN ACCOUNT_STATUS = 'EXPIRED'
THEN '2'
WHEN ACCOUNT_STATUS = 'EXPIRED(GRACE)'
THEN '3'
WHEN ACCOUNT_STATUS = 'LOCKED(TIME)'
THEN '4'
END AS ACCOUNT_STATUS
FROM DBA_USERS
WHERE USERNAME = (SELECT USERNAME FROM DBA_USERS WHERE USERNAME LIKE '%SYSTEM%' AND PROFILE NOT IN ('DEFAULT','MONITORING_PROFILE'))
/
EOF
}
function database_name() {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT NAME FROM V\$DATABASE;
EOF
}
function objetos_invalidos() {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT OBJECT_NAME FROM DBA_OBJECTS WHERE STATUS = 'INVALID' AND OWNER = '$1';
EOF
}
function usuarios_3_conectados () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT VS.SID FROM DBA_USERS U INNER JOIN V\$SESSION VS
ON VS.USER# = U.USER_ID
AND U.PROFILE IN ('CRMALL_3')
/
EOF
}
function db_archivelog_status () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
select (log_mode) from v\$database where log_mode = 'ARCHIVELOG';
EOF
}
function db_archived_last () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT NVL(MAX(TO_CHAR(COMPLETION_TIME,'DD/MM/YY HH24:MI:SS')),'None')
FROM V\$ARCHIVED_LOG
WHERE TO_CHAR(COMPLETION_TIME,'DD/MM/YY') = TO_CHAR(SYSDATE,'DD/MM/YY')
AND TO_CHAR(COMPLETION_TIME,'HH24') = TO_CHAR(SYSDATE,'HH24');
EOF
}
function db_archivelog_last_seq () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT (SEQUENCE#) FROM V\$ARCHIVED_LOG WHERE TO_CHAR(COMPLETION_TIME,'DD/MM/YY') = TO_CHAR(SYSDATE,'DD/MM/YY') AND TO_CHAR(COMPLETION_TIME,'HH24') = TO_CHAR(SYSDATE,'HH24');
EOF
}
function db_alive () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT 'ALIVE' FROM DUAL;
EOF
}
function db_total_size () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
col SUM(BYTES) format 999999999999999
SELECT SUM(BYTES) FROM DBA_DATA_FILES;
EOF
}
function db_used_size () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
col SUM(BYTES) format 999999999999999
SELECT SUM(BYTES) FROM DBA_SEGMENTS;
EOF
}
function db_version () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT TRIM(SUBSTR(BANNER,1,(INSTR(BANNER,' ',20)))) AS DB_VERSION FROM V\$VERSION WHERE BANNER LIKE '%Oracle Database%';
EOF
}
function db_release () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT TRIM(REGEXP_REPLACE(SUBSTR(BANNER,(INSTR(BANNER,'.',4))-2),'[^12357890.]+', '')) AS DB_RELEASE FROM V\$VERSION WHERE BANNER LIKE '%Oracle Database%';
EOF
}
function index_invalid () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT INDEX_NAME FROM DBA_INDEXES WHERE STATUS = 'UNUSABLE' AND OWNER = '$1';
EOF
}
function waits_controlfileio () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT to_char(sum(decode(event,'control file sequential read', total_waits, 'control file single write', total_waits, 'control file parallel write',total_waits,0))) ControlFileIO FROM V\$system_event WHERE 1=1 AND event not in ( 'SQL*Net message from client', 'SQL*Net more data from client','pmon timer', 'rdbms ipc message', 'rdbms ipc reply', 'smon timer');
EOF
}
function waits_directpath_read () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT to_char(sum(decode(event,'direct path read',total_waits,0))) DirectPathRead FROM V\$system_event WHERE 1=1 AND event not in ( 'SQL*Net message from ', 'SQL*Net more data from client','pmon timer', 'rdbms ipc message', 'rdbms ipc reply', 'smon timer');
EOF
}
function waits_file_io () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT to_char(sum(decode(event,'file identify',total_waits, 'file open',total_waits,0))) FileIO FROM V\$system_event WHERE 1=1 AND event not in ( 'SQL*Net message from client', 'SQL*Net more data from client', 'pmon timer', 'rdbms ipc message', 'rdbms ipc reply', 'smon timer');
EOF
}
function waits_latch () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT to_char(sum(decode(event,'control file sequential read', total_waits,
'control file single write', total_waits, 'control file parallel write',total_waits,0))) ControlFileIO
FROM V\$system_event WHERE 1=1 AND event not in (
'SQL*Net message from client',
'SQL*Net more data from client',
'pmon timer', 'rdbms ipc message',
'rdbms ipc reply', 'smon timer');
EOF
}
function waits_logwrite () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT to_char(sum(decode(event,'log file single write',total_waits, 'log file parallel write',total_waits,0))) LogWrite
FROM V\$system_event WHERE 1=1 AND event not in (
'SQL*Net message from client',
'SQL*Net more data from client',
'pmon timer', 'rdbms ipc message',
'rdbms ipc reply', 'smon timer');
EOF
}
function waits_multiblock_read () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT to_char(sum(decode(event,'db file scattered read',total_waits,0))) MultiBlockRead
FROM V\$system_event WHERE 1=1 AND event not in (
'SQL*Net message from client',
'SQL*Net more data from client',
'pmon timer', 'rdbms ipc message',
'rdbms ipc reply', 'smon timer');
EOF
}
function waits_other () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT to_char(sum(decode(event,'control file sequential read',0,'control file single write',0,'control file parallel write',0,'db file sequential read',0,'db file scattered read',0,'direct path read',0,'file identify',0,'file open',0,'SQL*Net message to client',0,'SQL*Net message to dblink',0, 'SQL*Net more data to client',0,'SQL*Net more data to dblink',0, 'SQL*Net break/reset to client',0,'SQL*Net break/reset to dblink',0, 'log file single write',0,'log file parallel write',0,total_waits))) Other FROM V\$system_event WHERE 1=1 AND event not in ( 'SQL*Net message from client', 'SQL*Net more data from client', 'pmon timer', 'rdbms ipc message', 'rdbms ipc reply', 'smon timer');
EOF
}
function waits_singleblock_read () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT to_char(sum(decode(event,'db file sequential read',total_waits,0))) SingleBlockRead
FROM V\$system_event WHERE 1=1 AND event not in (
'SQL*Net message from client',
'SQL*Net more data from client',
'pmon timer', 'rdbms ipc message',
'rdbms ipc reply', 'smon timer');
EOF
}
function waits_sqlnet () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT to_char(sum(decode(event,'SQL*Net message to client',total_waits,'SQL*Net message to dblink',total_waits,'SQL*Net more data to client',total_waits,'SQL*Net more data to dblink',total_waits,'SQL*Net break/reset to client',total_waits,'SQL*Net break/reset to dblink',total_waits,0))) SQLNET FROM V\$system_event WHERE 1=1 AND event not in ( 'SQL*Net message from client','SQL*Net more data from client','pmon timer','rdbms ipc message','rdbms ipc reply', 'smon timer');
EOF
}
function pga_aggregat_target () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
select decode( unit,'bytes', value, value) value from V\$PGASTAT where name in 'aggregate PGA target parameter';
EOF
}
function pga () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
select decode( unit,'bytes', value, value) value from V\$PGASTAT where name in 'total PGA inuse';
EOF
}
function sga_buffer_cache () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT to_char(ROUND(SUM(decode(pool,NULL,decode(name,'db_block_buffers',(bytes),'buffer_cache',(bytes),0),0)),2)) sga_bufcache FROM V\$SGASTAT;
EOF
}
function sga_fixed () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT (bytes) used_shard_pool FROM V\$SGASTAT WHERE NAME ='free memory' and pool = 'java pool';
EOF
}
function sga_java_pool () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT to_char(ROUND(SUM(decode(pool,'java pool',(bytes))),2)) sga_jpool FROM V\$SGASTAT;
EOF
}
function sga_large_pool () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT bytes used_shard_pool FROM V\$SGASTAT WHERE NAME ='free memory' and pool = 'large pool';
EOF
}
function sga_log_buffer () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT TO_CHAR(ROUND(SUM(decode(pool,NULL,decode(name,'log_buffer',(bytes),0),0)),2)) sga_lbuffer FROM V\$SGASTAT;
EOF
}
function sga_shared_pool_total () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT (spu.BYTES)+(spf.BYTES) as " "
from
(SELECT sum(bytes) as BYTES FROM V\$SGASTAT WHERE NAME !='free memory' and pool = 'shared pool') spu,
(SELECT sum(bytes) as BYTES FROM V\$SGASTAT WHERE NAME ='free memory' and pool = 'shared pool') spf;
EOF
}
function sga_shared_pool_used () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT sum(bytes) as " " FROM V\$SGASTAT WHERE NAME !='free memory' and pool = 'shared pool';
EOF
}
function sga_shared_pool_free () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT (bytes) as " " FROM V\$SGASTAT WHERE NAME ='free memory' and pool = 'shared pool';
EOF
}
function sga_target () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT VALUE FROM V\$PARAMETER WHERE NAME = 'sga_target';
EOF
}
function sga_max_size () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT VALUE FROM V\$PARAMETER WHERE NAME = 'sga_max_size';
EOF
}
function sga_free () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
select sum(bytes) as " "
From V\$sgastat
Where Name Like '%free memory%';
EOF
}
function sga_used () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
set numformat 99999999999999999999
select sum(bytes) as " " from v\$sgastat where name!='free memory';
EOF
}
function db_hit_rate () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SELECT ROUND(((1 - (SUM(GETMISSES) / (SUM(GETS) + SUM(GETMISSES)))) * 100),0 ) "Hit Rate"
FROM V\$ROWCACHE
WHERE GETS + GETMISSES <> 0;
EOF
}
function session_cached_cursor_value () {
$SQLPLUS -S $USERNAME/$PASSWORD <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF